Possible Duplicate:
How to put span element inside ActionLink MVC3?
How to create custom MVC3 ActionLink method that generates this output:
<li>
<a href="/Home/ControllerName" data-ajax-update="#scroll"
data-ajax-mode="replace" data-ajax-method="GET"
data-ajax-loading="#progress" data-ajax="true">
<span>LinkText</span> // this span generated inside <a>
</a>
</li>
You either create a new extension method that returns an MvcHtmlString
object that you put together yourself (mind the html encoding, though), our you create a partial view that you can render when you need it, so you don't have to create HTML through code.
public static class MyHtmlExtensions {
public static MvcHtmlString MyActionLink(this HtmlHelper html, string action, string controller, string ajaxUpdateId, string spanText) {
var url = UrlHelper.GenerateContentUrl("~/" + controller + "/" + action);
var result = new StringBuilder();
result.Append("<a href=\"");
result.Append(HttpUtility.HtmlAttributeEncode(url));
result.Append("\" data-ajax-update=\"");
result.Append(HttpUtility.HtmlAttributeEncode("#" + ajaxUpdateId));
// ... and so on
return new MvcHtmlString(result.ToString());
}
}
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