在TextBoxFor在MVC3控制名称 [英] control name in TextBoxFor in MVC3

查看:120
本文介绍了在TextBoxFor在MVC3控制名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能控制使用TextBoxFor时说文本boxt的name属性?

这code视图

  @ Html.TextBoxFor(M = GT; m.SearchParams.someParam)

生产这种

 <输入ID =SearchParams_someParamNAME =SearchParams.someParam类型=文本值=>

但我不希望我的输入名称为SearchParams.someParam,我想,要成为像

 <输入ID =SearchParams_someParamNAME =我的preferedName类型=文本值=>

在这里我的preferedName来自一些在相应的模型属性的.SearchParams.someParam。

这可能吗?我知道@ Html.TextBox做,但我不想硬code在视图名称。


解决方案

  @ Html.TextBoxFor(型号=> model.attr,新{名称=TXT1})

只是使用的名,而不是名

Is it possible to control the name attribute of say a text boxt when using TextBoxFor?

this code in the view

@Html.TextBoxFor(m => m.SearchParams.someParam)

produce this

<input id="SearchParams_someParam" name="SearchParams.someParam" type="text" value="">

but I do not want my input name to be "SearchParams.someParam" and I wanted that to be something like

<input id="SearchParams_someParam" name="MyPreferedName" type="text" value="">

where the MyPreferedName comes from from some attributes the .SearchParams.someParam in the corresponding model.

Is this possible? I know @Html.TextBox does it but I do not want to hardcode the name in the view.

解决方案

@Html.TextBoxFor(model => model.attr, new { Name = "txt1" })

Just Use "Name" instead of "name"

这篇关于在TextBoxFor在MVC3控制名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆