不工作的ASP.NET MVC 2 RC客户端验证 [英] ASP.NET MVC 2 RC client side validation not working

查看:162
本文介绍了不工作的ASP.NET MVC 2 RC客户端验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法得到任何客户端验证一个MVC 2 RC应用工作。

I can't seem to get any client side validation working on a MVC 2 RC app.

我的模型有以下几点:

public class ExampleModel
{
    [Required(ErrorMessage="Test1 is required")]
    [DisplayName("Test1")]
    public string Test1 { get; set; }

    [Required(ErrorMessage="Test2 is required")]
    [DisplayName("Test2")]
    public string Test2 { get; set; }
}

我的看法有以下code:

My view has the following code:

<% Html.EnableClientValidation(); %>
<%= Html.ValidationSummary(true, "Test was unsuccessful.") %>    
<% using (Html.BeginForm()) { %>
<div>
    <div class="editor-label">Test1:</div>
    <div class="editor-field">
        <%= Html.TextBoxFor(m => m.Test1) %>
        <%= Html.ValidationMessageFor(m => m.Test1) %>
    </div>

    <div class="editor-label">Test2:</div>
    <div class="editor-field">
        <%= Html.TextBoxFor(m => m.Test2) %>
        <%= Html.ValidationMessageFor(m => m.Test2) %>
    </div>

    <p>
        <input type="submit" value="Test" />
    </p>
</div>

我离开这两个领域的空白,并点击测试按钮,它会从右到控制器的处理后,没有客户端验证发生。我不知道我错过了什么。

I leave both fields blank and click the Test button and it goes right to the controller's post handler with no client side validation happening. I am not sure what I am missing.

我有以下的JavaScript也包含在视图(不知道我是否需要全部):

I have the following javascript also included in the view (not sure if I need it all):

<link href="../../Scripts/jquery-1.3.2.min.js" type="text/javascript" />
<link href="../../Scripts/jquery.validate.min.js" type="text/javascript" />    
<link href="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript" /> 

任何想法,我做错了。我觉得我失去了一些东西简单的MVC的文档2稀疏。

Any ideas what I am doing wrong. I feel like I am missing something simple and the documentation for MVC 2 is sparse.

编辑:我已经添加了链接:

&LT;链接HREF =../../脚本/ MicrosoftMvcJQueryValidation.js类型=文/ JavaScript的/&GT;

和我已经包括在我的项目文件,我不得不从对答案的链接下载。还是根本不工作。任何其他的想法?

And I have included the file in my project which I had to download from on of the links in the answers. Still not working at all. Any other ideas?

编辑:我使用Visual Studio 2008 MVC 2 RC(不是beta )和我正在寻找任何下载或贴有工作的客户端验证的例子RC版本。

I am using Visual Studio 2008 with MVC 2 RC (not beta) and I am looking for any downloadable or posted examples of client-side validation working with the RC release.

推荐答案

好吧,我想通了这一点......,这是100%,我的错。虽然一对夫妇的帖子包括一些信息,我也需要。

Ok I figured this out... and it is 100% my fault. Although, a couple of the posts included some information that I did need also.

主要的问题,对此我感到惊讶没有人注意到,当时我的HTML,包括脚本......在这个职位抬头见,如果你能看到的问题。

The main problem, which I am suprised no one noticed, was my HTML to include the scripts... look up at my post and see if you can see the problem.

我使用的是&LT;链接HREF = ... 标签,而不是正确的&LT;脚本的src = ... 标记。完全是我的错,因为我已经在迅速剪切和粘贴不假思索的CSS链接,只是改变了类型和文件。咄!

I was using a <link href=... tag instead of the proper <script src=... tag. Totally my fault as I had quickly cut and pasted the CSS link without thinking and just changed the type and file. Duh!!!

不管怎么说所需的正确链接:

Anyways the correct links required are:

<script src="/Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcJQueryValidation.js" type="text/javascript"></script>

一切正常即可。你肯定确实需要包括来自期货项目MicrosoftMvcJQueryValidation.js'文件,所以我upvoted是提到的所有帖子。

Everything works then. You definately do need to include the 'MicrosoftMvcJQueryValidation.js' file from the futures project so I am upvoted all the posts that mentioned that.

开箱,虽然该文件不包括在内。如果你不是使用JQuery那么你可以使用下面的担心包括使用Microsoft实现,它会与钢筋混凝土框的:

Out of the box though that file is NOT included. If your not worried about using JQuery then you can just use the following includes to use the Microsoft implementation which will work out of the box with the RC:

<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>    

我希望我可以节省至少一人悲伤一些......我仍然无法相信我怎么会搞砸了包括与没有注意到它SOOOOO长。

I hope I can save at least one person some grief... I still can't believe how I could have screwed up the include and not noticed it for sooooo long.

再次感谢您的帮助。

这篇关于不工作的ASP.NET MVC 2 RC客户端验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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