开发者

mvc actionlink show html tags

开发者 https://www.devze.com 2022-12-21 16:18 出处:网络
how can i show html tags like this 开发者_如何转开发html.actionlinlk(\"<b>bla bla</b>\", null)

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?


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:

<a href="<%=Url.Action("action", "controller")%>">Text</a>

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.


I think your looking for:

<b><%= Html.ActionLink("bla bla", null) %></b>

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消