问题描述
我是从asp.net迁移网站ASP.NET MVC
i am migrating a website from asp.net to asp.net mvc
在asp.net网站还有很多地方,他们有文字标签和服务器在文字标签生成一串HTML和棍棒的。
in the asp.net site there are many places where they have "literal" tags and the server generates a bunch of html and sticks in in the literal tag.
什么是在asp.net的MVC doign此相当。我应该在ViewData的推呢?
what is the equivalent of doign this in asp.net mvc. Should i shove this in ViewData?
推荐答案
相当于是不会犯同样糟糕的设计选择原来的开发商的。
The equivalent is to not make the same bad design choices the original developer made.
但是,因为我们生活在现实世界中,你会推自己的字符串,其中包含中,HTML到presentation型号为某一特定页面,然后将其写入响应流中。
But, since we live in the real world, you'd shove their strings-which-contain-html into the presentation model for a particular page and then write it to the response stream.
在你的模型:
public class MyPageModel
{
public string HolyCrapItsHtml {get;set;}
}
在你的控制器:
public ActionResult MyPage()
{
return View(new MyPageModel
{HolyCrapItsHtml = OldCode.GetHtmlICantBelieveIt()});
}
和在你的页面:
<div>
In the olden days, we'd concatenate our webpages together from strings like:
<%= Model.HolyCrapItsHtml %>
</div>
这篇关于什么是等价的&QUOT;字面&QUOT;标签在asp.net mvc的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!