Asp.Net MVC2客户方验证和ID重复的问题 [英] Asp.Net MVC2 Clientside Validation and duplicate ID's problem

查看:182
本文介绍了Asp.Net MVC2客户方验证和ID重复的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是VS2010 MVC2

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) %>

如果我使用一个网页上同时显示局部视图,它最终有重复的ID,以便验证通过这两个观点发生(甚至thopugh他们是在单独的形式)

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)

我怎么能去消除这种

推荐答案

对于某些控件可以指定HTML在过载的属性是这样的:

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" }) %>

您也可以用手工写HTML或使用旧的HTML佣工,所以你可以添加自己的ID的方式(需要为 Html.LabelFor做到这一点()佣工)

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" } ) %>

这篇关于Asp.Net MVC2客户方验证和ID重复的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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