i want to create my own TextBox Helper that do a simple thing: wraps the input element with some divs and labels, like this:
<div class="col-xs-12">
<label>field name</label>
<div>
<input id='myId' name='MyName' type='text' value='myValue'>
</div>
</div>
In the view, i want to call it this way:
@Html.TextBox("Name")
How can I do this? There is a way to call base class in my helper?
Update: a better solution
After Krishina answer, I got a better approach, using code like this:
public static MvcHtmlString CliTextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string LabelText, object htmlAttributes)
{
var baseFormat = htmlHelper.TextBoxFor(expression, format: null, htmlAttributes: htmlAttributes);
var errors = htmlHelper.ValidationMessageFor(expression, "", new { @class = "text-danger" }).ToString();
if (!string.IsNullOrEmpty(errors))
errors = "<div>" + errors + "</div>";
var wrap = String.Format(
"<div class='col-xs-12'>" +
"<label>{0}</label>" +
"<div>{1}</div>"+
"{2}" +
"</div>", LabelText, baseFormat.ToString(), errors);
return new MvcHtmlString(wrap);
}
In this way, I keep using TextBoxFor to generate the base input element.