Custom Html Helpers in MVC
namespace MVCCustomeHtmlHelper
{
public static class CustomHtmlHelpers
public static IHtmlString Image(this HtmlHelper helper, string src, string alt)
TagBuilder tagBuilder = new TagBuilder(“img”);
tagBuilder.Attributes.add(“src”, VartualPathUtility.ToAbsolute(src));
tagBuilder.Attributes.add(“alt”,alt);
return new
MvcHtmlString(tagBuilder.ToString(TagRenderMode.SelfClosing));
}
<img src=”@Url.Content(@Model.Photo)” alt=”@Model.AlternateText” /> or
@Html.Image(Model.Photo, Model.AlternateText)
<system.web.webPages.razor>
<pages pageBaseType=”System.Web.Mvc.WebViewPage”>
<namespaces>
<add namespace=” MVCCustomeHtmlHelper” />
</namespaces>
</pages>
</ system.web.webPages.razor>
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: