mvc div中嵌入html页面,在MVC 3中以div标签呈现HTML(Render HTML in div tag in MVC 3)

在MVC 3中以div标签呈现HTML(Render HTML in div tag in MVC 3)

我在db中有一个存储html的字段,我想在用户端呈现该html。 但我无法这样做。 当我试图把html放在div标签或段落标签,然后我得到简单的HTML文本。 这是我试过的代码

我使用这个得到以下结果(HTML显示为文本)

Enter custom CSS code into the box below to further customize your mobile site.

I have a field in db which stores html and i want to render that html on userside. but i am unable to do so. when i tried to put html in div tag or paragraph tag then i get simply html text. here is my code which i tried

and i get following result by using this (HTML appears as text)

Enter custom CSS code into the box below to further customize your mobile site.

原文:https://stackoverflow.com/questions/12312917

更新时间:2019-12-01 22:38

最满意答案

尝试使用Html.Raw输出您的HTML:

@Html.Raw(Model.HomePageText)

Try using Html.Raw to output your HTML:

@Html.Raw(Model.HomePageText)

相关问答

使用@Url.Action()获取href值而不是@Html.ActionLink Use @Url.Action() to get href value instead of @Html.ActionLink

您可以使用正则表达式替换您的html标记。 例如, string myContent = Regex.Replace(description, @"", string.Empty);

或者 - 你可以使用.Net 4.0+的WebUtility.HtmlDecode和旧版本的HttpUtility.HtmlDecode 。 希望能帮助到你 :) You can use regex to replace your html tags. For example, string m

...

尝试使用Html.Raw输出您的HTML:

@Html.Raw(Model.HomePageText)

Try using Html.Raw to output your HTML:

@Html.Raw(Model.HomePageText)

解决方案是使用Url.Action方法。

Home

希望它可以帮助别人。 The Solution is to use the Url.Action Method.

...

第一个先决条件是拥有一个支持标签的浏览器(IE 9.0 +,FireFox 3.5 +,Safari 3.0 +,Chrome 3.0 +,Opera 10.5 +,iPhone 1.0 +,Android 2.0 +,...)。 然后你可以像这样使用它:

Your browser does not support the video tag

或者,如果

...

在控制器中使用 model.MyLink = HttpUtility.HtmlDecode(url);

然后在视图中使用 @Html.Raw(Model.MyLink)

第一个转换它使用 In the controller use model.MyLink = HttpUtility.HtmlDecode(url);

then in the view use @Html.Raw(Model.MyLink)

The first converts it to use

通过'编程',我认为你在页面加载后使用JavaScript来替换DIV的内容? 如果将DIV设置为硬宽度(通过CSS或内联HTML),请确保“溢出”CSS属性未设置为“隐藏”或“滚动”。 然后,这应该按照正常的HTML呈现来包装HTML,并在必要时强制DIV高度的高度。 如果您有一行非常长的文本没有中断,或者图像的宽度比DIV更宽,则如果您具有专门设置的宽度,则DIV不会展开。 By 'programmatically', I presume you're using JavaScript to

...

尝试这个: @foreach (Games.Models.GameDetail Lnk in Model.oListSpace)

{

@Lnk.Name

@if(System.IO.File.Exists(Server.MapPath("~") +"\\pictures\\g

...

Spring不关心你在jsp文件中使用什么标签。 浏览器呢。 为HTML5使用正确的文档类型是:

Spring doesn't care what tags you use in your jsp files. The browser does. Use a correct document type for HTML5 is all:

这应该这样做:

@Html.Raw(Model.HtmlString)

This should do it:

@Html.Raw(Model.HtmlString)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值