我想在浏览器中运行html标签但是......

我想在浏览器中运行html标签但是......

问题描述:

我想在浏览器中运行html标签,但是当我通过以下代码发送带有viewbag的html标签时,



I want to run html tags in browser but
when I send html tags with viewbag by below code

ViewBag.Content="<h1>hello every body</h1>"



然后我在视图中看到它

输出< h1>你好每个身体< / h1>

请给我一个解决方案


then I read it in view
output is <h1>hello every body</h1>
please give me a solution

您好Kave.Dear在课堂上创建一个类和这样的属性:



Hi Kave.Dear create a class and a property like this in class:

[AllowHtml]
[DataType(DataType.MultilineText)]
[Display(Name = "MyHtmlText")]
public string Description { get; set; }



所以把你的html文本放到这个属性中,



并进入你的视图试试这个:




So put your html text into this property,

And Into your view try this:

@Html.Raw(Model.Description)


@Html.Raw("<h1>HTML</h1>")





或其他解决方案





or other solution

@MvcHtmlString.Create("<h1>HTML</h1>")


为什么你使用ViewBag这样做是超出我的。这可能是一个简单的试验和错误实验,但无论如何...



你还没有展示你是如何尝试在视图中渲染它的(假设你在.cshtml文件中使用Razor)所以几乎不可能准确地回答你的问题。
Why you're using the ViewBag to do this is beyond me. This could be a simple trial and error experiment on your part, but whatever...

You haven't shown how you're trying to render this in the view (assuming you're using Razor, in the .cshtml file) so it's pretty much impossible to answer your question with any accuracy.