[英]Remote Validation Incorrect URL
I am using MVC's remote validation in my web application. 我在Web应用程序中使用了MVC的远程验证。 When I attempt to use the
Remote[]
validation attribute 当我尝试使用
Remote[]
验证属性时
[Remote("EmailExists", "Validation")]
public string EmailAddress { get; set; }
I expect this email address to reach out to my ValidationController
and call the method EmailExists
. 我希望这个电子邮件地址可以到达我的
ValidationController
并调用方法EmailExists
。
public class ValidationController : Controller
{
public JsonResult EmailExists(string emailAddress)
{
return Membership.GetUser(emailAddress) != null ?
Json("true", JsonRequestBehavior.AllowGet) :
Json("Email does not exist", JsonRequestBehavior.AllowGet);
}
}
With the rendered HTML looking something like this 呈现的HTML看起来像这样
<input class="form-control" data-val="true" data-val-remote="'EmailAddress' is invalid." data-val-remote-additionalfields="*.EmailAddress" data-val-remote-url="/IdSrv/Validation/EmailExists" id="EmailAddress" name="EmailAddress" type="text" value="">
But instead, if you look at the data-val-remote-url
you will notice it renders something completely different when the HTML actually renders 但是,相反,如果您查看
data-val-remote-url
您会注意到,当HTML实际呈现时,它呈现的东西完全不同。
<input class="form-control" data-val="true" data-val-remote="'EmailAddress' is invalid." data-val-remote-additionalfields="*.EmailAddress" data-val-remote-url="/IdSrv/issue/wstrust?controller=Validation&action=EmailExists" id="EmailAddress" name="EmailAddress" type="text" value="">
I am using ThinkTecutre Identity Provider, but I'm not sure why the default route set up by the Remote
validation is incorrect. 我正在使用ThinkTecutre Identity Provider,但是我不确定为什么
Remote
验证设置的默认路由不正确。 Am I doing something wrong, or is there something I can change to point the URL to the correct location? 我是在做错什么,还是可以更改一些以将URL指向正确的位置?
Make sure you don't any custom routing defined in RoutingConfig.cs
before default routing. 确保没有默认路由之前在
RoutingConfig.cs
定义的任何自定义路由。
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Try matching Property name with action method parameter 尝试将属性名称与操作方法参数匹配
public JsonResult EmailExists(string EmailAddress)
{
}
Check below links for more details. 检查以下链接以获取更多详细信息。
http://msdn.microsoft.com/en-us/library/gg508808%28vs.98%29.aspx http://msdn.microsoft.com/zh-cn/library/gg508808%28vs.98%29.aspx
http://www.codeproject.com/Tips/669824/Implementing-Remote-Validation-in-MVC http://www.codeproject.com/Tips/669824/Implementing-Remote-Validation-in-MVC
http://www.codeproject.com/Articles/674288/Remote-Validation-in-MVC-Simple-Way-to-Pass-the-F http://www.codeproject.com/Articles/674288/Remote-Validation-in-MVC-Simple-Way-to-Pass-the-F
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.