Asp.Net MVC2 客户端验证和重复 ID 的问题
我在 VS2010 中使用 MVC2
我有一个视图,其中有两个部分视图:“登录”和“注册”
两个部分视图都包含电子邮件地址字段,我在两个部分视图中使用以下内容:
<%: Html.TextBoxFor(model => model.EmailAddress ) %><br /><%: Html.ValidationMessageFor(model => model.EmailAddress) %>
如果我在一页上,它最终会出现重复的 id,因此验证会在两个视图中进行(即使它们采用不同的形式)
我该如何消除这个问题
I'm using MVC2 with VS2010
I have a view that has two partial views in it: "Login" and "Register"
both partial views contains the Email address field i use the following in both partial views:
<%: Html.TextBoxFor(model => model.EmailAddress ) %><br /><%: Html.ValidationMessageFor(model => model.EmailAddress) %>
if i use both partial views on one page, it ends up having duplicate id's so validation happens across both views (even thopugh they are in seperate forms)
how can i go about eliminating this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于某些控件,您可以在重载中指定 HTML 属性,如下所示:
您还可以手动编写 HTML 或使用旧的 HTML 帮助程序,这样您就可以通过这种方式添加您自己的 ID(您需要为
Html 执行此操作.LabelFor()
帮助器)For some controls you can specify the HTML attributes in an overload like this:
You can also either write your HTML by hand or use the older HTML helpers so you can add your own ID that way (you need to do this for
Html.LabelFor()
helpers)