我想在浏览器中运行html标签但是...... [英] I want to run html tags in browser but...

查看:63
本文介绍了我想在浏览器中运行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.


这篇关于我想在浏览器中运行html标签但是......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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