我如何使用MVC3剃刀呈现从Viewbag HTML [英] How do I render HTML from the Viewbag using MVC3 Razor

查看:178
本文介绍了我如何使用MVC3剃刀呈现从Viewbag HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Viewbag到表单元素传递到一个MVC3视图,只是写HTML页面...

I am trying to pass a form element into an MVC3 view by using the Viewbag and simply write the HTML to the page ...

在控制器:

ViewBag.myData = "<input type=""hidden"" name=""example"" value=""examplevalue"">";

在视图(我知道我可以使用的形式助手):

In view (I know I could use a helper for the form):

<form action="http://exampleurl/examplepage" method="post" id="example-form">
@ViewBag.myData
<input type="hidden" name="anotherexample" value="anotherexamplevalue" />
</form>

这呈现的myData作为HTML文本即:

This renders the myData as text in the HTML i.e.:

 &lt;type="hidden" name="example" value="examplevalue"&gt; 

所以我的问题是如何得到剃刀做相当于旧的:

So my question is how do I get Razor to do the equivalent of older:

<%= myData %>

而不是取代的&lt;>

and not replace the <>

谢谢
保罗

推荐答案

使用 @ Html.Raw(ViewBag.Mydata)

这篇关于我如何使用MVC3剃刀呈现从Viewbag HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆