I am trying to create a custom Html helper with ASP.NET MVC. I have the following code:
@helper DefaultRenderer(Models.Control control)
{
<div class="form-group">
<label class="control-label" for="@control.Name">@control.Label</label>
@Html.TextBoxFor(m => control.Value, new { @class = "form-control" })
</div>
}
Apparently @Html.TextBoxFor cannot be found inside a Helper .cshtml class. I can use it in a partial view which is also a .cshtml class.
I can use @HtmlTextBox but then I will lose the strong model binding...
Why is this happening and is there a way to get it to work?
No, this is not possible. You could not write a normal HTML
helper
with@Html.TextBoxFor
because that your view is strongly typed. So you need something like:Then you can use :