简体   繁体   English

尝试使用远程字段验证

[英]Trying to use remote field validation

I'm just trying to make this work for the first time: http://msdn.microsoft.com/en-us/library/gg508808%28v=vs.98%29.aspx 我只是想第一次使这项工作: http : //msdn.microsoft.com/zh-cn/library/gg508808%28v=vs.98%29.aspx

In my model I have 在我的模型中

    [Remote("RequireName", "Contact")]
    [Editable(true)]
    public string Name { get; set; }

In my controller I have 在我的控制器中

public JsonResult RequireName(string Name)
    {
        bool resultbool = ((Name != null) && (Name.Length > 0));
        return this.Json(resultbool ? "OK." : "Not OK.", JsonRequestBehavior.AllowGet);
    }

(I don't care about it's result message for now.) (我现在不在乎它的结果消息。)

In my resulting HTML I have: 在生成的HTML中,我有:

<input type="text" value="" name="Name" id="Name" data-val-remote-url="/[mysite]/Contact/RequireName" data-val-remote-additionalfields="*.Name" data-val-remote="'Name' is invalid." data-val="true" class="text-box single-line">

URL http://localhost/[mysite]/Contact/RequireName returns "Not OK.", which is correct. URL http:// localhost / [mysite] / Contact / RequireName返回“不正确。”,这是正确的。 URL http://localhost/[mysite]/Contact/RequireName?Name=something returns "OK.", which is correct. URL http:// localhost / [mysite] / Contact / RequireName?Name = something返回“确定”,这是正确的。

But when I edit the field or even when I submit the complete form, validation does not happen. 但是,当我编辑字段或提交完整的表单时,不会进行验证。 I'm sure I'm missing something. 我确定我想念什么。 Thank you if you can help me. 谢谢您的帮助。

After some more Internet search, I understood that I had to include "jquery.validate.min.js" and "jquery.validate.unobtrusive.js". 经过更多的Internet搜索之后,我了解到必须包含“ jquery.validate.min.js”和“ jquery.validate.unobtrusive.js”。 Sounds basics but I had not clue about it yet. 听起来很基础,但我还不知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM