解决方法
这应该是诀窍:
- public static class MyInputExtensions
- {
- public static MvcHtmlString NameLessTextBoxFor<TModel,TProperty>(this HtmlHelper<TModel> htmlHelper,Expression<Func<TModel,TProperty>> expression)
- {
- var textBox = htmlHelper.TextBoxFor(expression);
- string pattern = @"name=""([^""]*)""";
- string fixedHtml = Regex.Replace(textBox.ToHtmlString(),pattern,"");
- return new MvcHtmlString(fixedHtml);
- }
- }
用法:
- @Html.NameLessTextBoxFor(x=> x.CustomerId)