Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting raw text using @Html.ActionLink in Razor / MVC3?

Given the following Html.ActionLink:

@Html.ActionLink(Model.dsResults.Tables[0].Rows[i]["title"].ToString(), "ItemLinkClick",
    new { itemListID = @Model.dsResults.Tables[0].Rows[i]["ItemListID"], itemPosNum = i+1 }, ...

Data from the model contains HTML in the title field. However, I am unable to display the HTML encoded values. ie. underlined text shows up with the <u>....</u> around it.

I've tried Html.Raw in the text part of the ActionLink, but no go.

Any suggestions?

like image 885
ElHaix Avatar asked Aug 01 '11 17:08

ElHaix


People also ask

What is Html ActionLink ()?

Html. ActionLink creates a hyperlink on a view page and the user clicks it to navigate to a new URL. It does not link to a view directly, rather it links to a controller's action.

What is difference between Html ActionLink and URL action?

Yes, there is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.

What does Html raw do C#?

Raw allows you to output text containing html elements to the client, and have them still be rendered as such. Should be used with caution, as it exposes you to cross site scripting vulnerabilities.

How do you change the ActionLink color in Html?

@Html. ActionLink("name", "Action", "Controler", new { id= sentId, Style = "color:White" }, null);


1 Answers

If you still want to use a helper to create an action link with raw HTML for the link text then I don't believe you can use Html.ActionLink. However, the answer to this stackoverflow question describes creating a helper which does this.

I would write the link HTML manually though and use the Url.Action helper which creates the URL which Html.ActionLink would have created:

<a href="@Url.Action("ItemLinkClick", new { itemListID = @Model.dsResults.Tables[0].Rows[i]["ItemListID"], itemPosNum = i+1 })">
    @Html.Raw(Model.dsResults.Tables[0].Rows[i]["title"].ToString())
</a>
like image 199
dan Avatar answered Oct 24 '22 02:10

dan