MVC3剃刀远程验证-控制器参数始终为空 [英] MVC3 razor remote validation - Controller argument is always empty

查看:75
本文介绍了MVC3剃刀远程验证-控制器参数始终为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以调用控制器,但参数(字符串)始终为空.

I can call the controller but the argument (string) is always null.

我发现的所有示例都将控制器参数命名为与我们正在远程验证的属性相同的参数,听起来不错/很容易,但是如果您查看提琴手,真正传入的是输入语句中的name属性.嗯,这是有问题的,因为它是带下标的名称,例如Person.EMailAddresses[0].Address,我不能这样命名控制器参数.

All the examples I have found name the controller argument the same as the property we are validating remotely, sounds good/easy, but if you look at fiddler what is really being passed in is the name attribute from the input statement. Well that is problematic in that it is a subscripted name something like Person.EMailAddresses[0].Address, well I can't name my controller parameter like that.

那么我该如何解决呢?必须有一种方法可以在remote()属性中指定控制器参数名称吗?

So how do I get around this? There must be a way to specify the controllers parameter name in the remote() attribute?

推荐答案

使用默认的RemoteAttribute无法完成. 这是我发布的有关可重复使用的远程验证属性的示例的链接,您可以在其中指定控制器的名称,操作以及用于将值传递给操作的变量的名称.

It cannot be done using the default RemoteAttribute. This is a link to an example I posted of a reusable remote validation attribute, where you can specify the name of the controller, action and the name of the variable used to pass the value to the action.

这篇关于MVC3剃刀远程验证-控制器参数始终为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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