[英]Remote Validation - No url for remote validation could be found mvc 5 C#
I am currently working on a 4 tier application, Core, Data, Shared, UI currently how it stands all our models are located inside the Shared project which is a class Library in one of the models we have the following implementation: 我目前正在研究4层应用程序,即Core,Data,Shared,UI,目前的样子我们所有的模型都位于Shared项目中,Shared项目是其中一个具有以下实现的模型之一的类库:
[Remote("UsernameUnique", "Register")]
[Required]
public string Username { get; set; }
This currently points to a Json method which is located inside the Register controller which is a part of the UI project as shown here, 当前,这指向位于Register控制器内部的Json方法,该方法是UI项目的一部分,如下所示,
public JsonResult UsernameUnique(UserRegistrationPartOne model)
{
var t = model;
return Json(false, JsonRequestBehavior.AllowGet);
}
But when I run this project and navigate to the sign up part it throws the error No url for remote validation could be found. 但是,当我运行该项目并导航到注册部分时,它会引发错误:找不到远程验证的URL。 I have been looking at the following just confirm I hadn't missed anything:
我一直在查看以下内容,只是确认我没有错过任何东西:
Remote Validaion inside MVC MVC内部的远程验证
According to what they do and what I've done is pretty much Identical, the only thing that I could think off which would be causing this problem is the fact the model is located in the Shared Project whilst its required on a view which is located in the UI Project? 根据他们所做的事情和我所做的事情几乎是相同的,我能想到的唯一会导致此问题的事实是,模型位于共享项目中,而模型在视图中是必需的在UI项目中? or maybe it could be something else?
也许可能是其他?
Your method needs to be 您的方法需要
public JsonResult UsernameUnique(string Username)
A RemoteAttribute
sends back the value of the property (not a model) RemoteAttribute
发回属性的值(不是模型)
Side note: If you need to send back other properties of your model in order to do the validation, then you can use the AdditionalFields
property of RemoteAttribute
旁注:如果需要发回模型的其他属性以进行验证,则可以使用
RemoteAttribute
的AdditionalFields
属性
public JsonResult UsernameUnique(string userName)
{
/// Checking your validation
return Json(false, JsonRequestBehavior.AllowGet);
}
if you want add additional field you can add to Action like 如果您想添加其他字段,可以将其添加到“操作”中,例如
public JsonResult UsernameUnique(string userName, FieldType additionalValue)
And Update the remote attribute like: 并更新如下的远程属性:
[Remote("UsernameUnique", "Register", AdditionalFields = "YourPropName"))]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.