ASP.Net MVC 3 中的远程验证:如何在操作方法中使用AdditionalFields
我一直在使用新的 ASP.Net MVC 3 RemoteAttribute 将远程调用发送到具有单个参数的操作方法。现在我想使用AdditionalFields 属性传入第二个参数:
[Remote("IsEmailAvailable", "Users", AdditionalFields = "InitialEmail")]
其中IntialEmail 是视图中的隐藏字段。该操作如下所示:
public JsonResult IsEmailAvailable(
string email,
string InitialEmail)
{
//etc.
}
当呈现视图时,隐藏字段被填充,但是当远程触发 Action 方法时,该值是一个空字符串。
我在其他地方看到大小写敏感可能是一个问题,因此我确保 Action 方法的两个参数具有相同的大小写。
还有其他建议吗?这个AdditionalFields过去被称为Fields。
谢谢,
美丽
I've been using the new ASP.Net MVC 3 RemoteAttribute to send a remote call to an action method that had a single parameter. Now I want to pass in a second parameter using the AdditionalFields property:
[Remote("IsEmailAvailable", "Users", AdditionalFields = "InitialEmail")]
Where IntialEmail is a hidden field in the view. The action looks like so:
public JsonResult IsEmailAvailable(
string email,
string InitialEmail)
{
//etc.
}
When the view is rendered, the hidden field is populated, but when the Action method is triggered remotely, the value is an empty string.
I've seen elsewhere case sensitivity may be an issue, so I've ensured the Action method has the same case for both parameters.
Any other suggestions? This AdditionalFields used to be called Fields.
Thanks,
Beaudetious
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
奇怪的。它对我有用:
模型:
控制器:
视图:
IIRC ASP.NET MVC 3 RC2 中存在一些错误,此远程验证已在 RTM 中修复。
Strange. It works for me:
Model:
Controller:
View:
IIRC there was some bug in ASP.NET MVC 3 RC2 with this remote validation that was fixed in the RTM.
您的隐藏字段必须与您正在验证的字段位于同一表单内(就像 Darin 的示例中那样),否则隐藏字段的值将不会作为参数发送到验证操作方法“public ActionResult IsEmailAvailable(string email, string initialEmail) )”
Your hidden field must be inside the same form as the field your are validating ( like it is in Darin's example ), otherwise the hidden field's value will not be sent as parameter to the validation action method "public ActionResult IsEmailAvailable(string email, string initialEmail)"
function IsEmailAvailable(string email, string initialEmail) param email 应为 Email,与 Property Email 完全相同。
function IsEmailAvailable(string email, string initialEmail) param email should as Email which exactly same as Property Email.