Asp.Net MVC2 客户端验证和重复 ID 的问题

发布于 2024-08-29 12:30:26 字数 348 浏览 2 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮色兮凉城 2024-09-05 12:30:26

对于某些控件,您可以在重载中指定 HTML 属性,如下所示:

<%: Html.TextBoxFor(model => model.EmailAddress, new { id = 'my-unique-id" }) %>
<br />
<%: Html.ValidationMessageFor(model => model.EmailAddress, new { id = 'my-unique-id" }) %>

您还可以手动编写 HTML 或使用旧的 HTML 帮助程序,这样您就可以通过这种方式添加您自己的 ID(您需要为 Html 执行此操作.LabelFor() 帮助器)

<%: Html.TextBox( "EmailAddress", Model.EmailAddress, new { id = 'my-unique-id" } ) %>

For some controls you can specify the HTML attributes in an overload like this:

<%: Html.TextBoxFor(model => model.EmailAddress, new { id = 'my-unique-id" }) %>
<br />
<%: Html.ValidationMessageFor(model => model.EmailAddress, new { id = 'my-unique-id" }) %>

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)

<%: Html.TextBox( "EmailAddress", Model.EmailAddress, new { id = 'my-unique-id" } ) %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文