Possible Duplicate:
Razor syntax prevent escaping html in an action link
How can I generate link, which contains image, using ASP.NET MVC Razor view engine @Html.ActionLink()
method. This method takes inner link text as first parameter, so I tried:
@{
string linkInnerHtml = string.Format("<img src=\"{0}\" /> Tiles", MyClass.GetImgSrc());
}
@Html.ActionLink(linkInnerHtml, "action" ... )
but, as a result, I got link with <img src="/source.img" /> Tiles
inner text. HTML didn't render.
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.
Yes, there is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.
Razor is a powerful templating implementation that's very useful to generate text and HTML output for all sorts of purposes. As you've seen in this article, you can use ASP.NET MVC Razor views from just about anywhere in your ASP.NET applications fairly easily with the Helper class provided here.
ActionLink is rendered as an HTML Anchor Tag (HyperLink) and hence it produces a GET request to the Controller's Action method which cannot be used to send Model data (object). Hence in order to pass (send) Model data (object) from View to Controller using @Html.
Write it out longhand, using Url.Action
to render the href
attribute value.
<a href="@Url.Action("action"...)">
<img src="@MyClass.GetImgSrc()" /> Tiles
</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With