4

ヘルパーを拡張して、次のようにします。


@html.TextBoxFor(x=>x.CustomerId).ReadOnly()

サーバーに投稿されないように、 name 属性なしで入力要素を出力します。

4

2 に答える 2

3

これでうまくいくはずです:

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)
于 2012-09-07T07:38:53.553 に答える