ASP.NET MVC 3:越权QUOT;名"与TextBoxFor属性 [英] ASP.NET MVC 3: Override "name" attribute with TextBoxFor

查看:135
本文介绍了ASP.NET MVC 3:越权QUOT;名"与TextBoxFor属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Html.TextBoxFor 覆盖name属性?

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

我曾尝试没有成功。我需要使用TextBoxFor获得客户端验证工作,但是,对于原因,我不会进入我需要的文本框的名称是从生成的不同。

I have tried with no success. I need to use TextBoxFor to get client side validation to work, however for reasons I won't go into I need the name of the textbox to be different from the generated one.

我曾尝试以下内容:

@Html.TextBoxFor(x => x.Data, new { name = Model.Key + "_Data", id = Model.Key + "_Data" })

这为ID的作品,但不能命名。这可能吗?

Which works for ID but not name. Is this possible?

更新:展望code表示TextBoxFor。它看起来并不像有一个简单的方法。希望有人能证明我错了。

Update: Looking into the code for TextBoxFor. It doesn't look like there is an easy way. Hopefully someone can prove me wrong.

推荐答案

你可以想应用preFIX?对于这一点,你可以在你的控制器设置 ViewData.TemplateInfo.HtmlField preFIX

Would you be wanting to apply a prefix? For that, you can set ViewData.TemplateInfo.HtmlFieldPrefix in your Controller.

我学到了很多关于这个东西从<一个href=\"http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-1-introduction.html\">Brad威尔逊的博客。

I learnt a lot about this stuff from Brad Wilson's blog.

这篇关于ASP.NET MVC 3:越权QUOT;名&QUOT;与TextBoxFor属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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