2012-08-22 101 views
0

动态HTML内容在我的.Net MVC 3应用程序页面,我需要做此功能: 当按钮用户点击,它应该navagate他到一些网页,但与HTML内容,我在模型属性。可能吗?显示视图从模型属性

回答

2

当然,在视图中:

@model MyViewModel 
@{ 
    Layout = null; 
} 
@Html.Raw(Model.SomePropertyThatContainsHtml) 

但是,这是完全荒谬的,你宁愿有你的控制器动作直接返回ContentResult

public ActionResult SomeAction() 
{ 
    MyViewModel model = ... 
    return Content(model.SomePropertyThatContainsHtml, "text/html"); 
} 
3

是的,这是可能的。 这一新的观点使用

@Model YourModel 
@{ 
    Layout = null; 
} 
@Html.Raw(Model.Propery) 
+0

感谢,那么请使用建议我创建新视图,并在其上添加一些动态内容?在这个视图中,它只是我需要的代码? – revolutionkpi

+0

更新我的答案。 –