ASP.NET MVC 3: Override “name” attribute with TextBoxFor

前端 未结 11 1534
臣服心动
臣服心动 2020-11-28 05:41

Is it possible when using Html.TextBoxFor to override the name attribute?

I have tried with no success. I need to use TextBoxFor to get client side vali

11条回答
  •  伪装坚强ぢ
    2020-11-28 06:15

    Try EditorFor. you can pass string as template name if you want to make sure textbox is rendered even if property type is not string. If property is string already, it does not need templatename explicitly to render textbox, so you can pass null. Note that it does not require id parameter explicitly, it will infer it from element name. And all the validation things are still active with EditorFor

     @Html.EditorFor(x => x.Data, "string", Model.Key + "_Data")
    

提交回复
热议问题