ヘルパーを拡張して、次のようにします。
@html.TextBoxFor(x=>x.CustomerId).ReadOnly()
サーバーに投稿されないように、 name 属性なしで入力要素を出力します。
ヘルパーを拡張して、次のようにします。
@html.TextBoxFor(x=>x.CustomerId).ReadOnly()
サーバーに投稿されないように、 name 属性なしで入力要素を出力します。
これでうまくいくはずです:
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)