I'm trying to create a custom HTML helper and I would like to know how I can access the Model object without passing it as a parameter.
Thanks
If you are using strongly typed views which you should:
public static MvcHtmlString MyHelper<TModel>(this HtmlHelper<TModel> htmlHelper)
{
TModel model = htmlHelper.ViewData.Model;
return MvcHtmlString.Empty;
}
If you are not using strongly typed views which you shouldn't:
public static MvcHtmlString MyHelper(this HtmlHelper htmlHelper)
{
object model = htmlHelper.ViewData.Model;
return MvcHtmlString.Empty;
}
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