mvc actionlink显示html标签
我怎样才能显示像这样的html标签,
html.actionlinlk("<b>bla bla</b>", null)
它显示bla bla而不是粗体bla bla-是否可以显示粗体文本?
how can i show html tags like this
html.actionlinlk("<b>bla bla</b>", null)
it dislay bla bla not bold bla bla-is it possible to show bold text?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我非常同意达林·季米特洛夫的观点。你不应该将 html 存储在你的数据库中。但无论如何你都可以解决这个问题。您可以使用 Url.Action 并自行编写
标记。像这样:
或者你必须为actionlink构建你自己的html扩展,因为默认的(正确的)html对你输入的值进行编码。
我建议第一个,因为我认为你应该自己编写html而不是使用帮手。编写
标记并不难。
I strongly agree with Darin Dimitrov. You should not store html in your db. But you can solve this problem anyway. Ether you use Url.Action and write the
<a />
tag your self. Like this:Or you will have to build your own html extension for actionlink as the default one (correctly) html encodes the value you put in.
I would suggest the first one as I think you should write the html your self instead of using a helper. It's not hard to write a
<a />
tag.我认为您正在寻找:
更新
好吧,我明白您在寻找什么。 ActionLink 扩展方法的第一个参数是(锚元素的)链接文本。据我所知它应该支持 HTML 标签。
例如
stackoverflow
为您提供 堆栈溢出I think your looking for:
Update
Ah ok I see what you are looking for. Well the first parameter of the ActionLink extension method is the link text (of the anchor element). As far as I am aware it should support HTML tags.
e.g.
<a href="http://stackoverflow.com">stack<b>overflow</b></a>
gives you stackoverflow数据库是用来存储数据的。 HTML 是标记。不要将 HTML 存储在数据库中。当您混合数据和标记时,您现在需要从标记和格式 (
) 中提取数据 (
bla bla
)。有一些工具允许您解析 HTML,例如 HTML Agility Pack。您始终可以尝试使用正则表达式解析它,但正如您所看到的 不建议这样做。所以我的建议是修改您的设计并将标记与实际数据分开。
Databases are for storing data. HTML is markup. Don't store HTML inside a database. As you've mixed data and markup you will now need to extract the data (
bla bla
) from the markup and formatting (<b>
). There are tools allowing you to parse HTML such as HTML Agility Pack. You could always try parsing it with a regular expression but as you may see this is not recommended.So my suggestion is to modify your design and separate markup from real data.
我对这个问题的解决方案是创建一个扩展方法。您可以在此处阅读(简短的)完整故事。
My solution about this problem was to create an extension method. You can read the (short) full story here.