I have been trying this based on Scott Gu's blog: http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx
My problem is that although my scripts are running (checked in firebug) and I don't get any errors. My page is still going to the server. I have javascript enabled too ;)
I have the following view code:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Part1a.ViewModels.ProductModel>" %>
Create
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
<h2>Create Product</h2>
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm()) {%>
<fieldset>
<legend>Fields</legend>
<%= Html.LabelFor(model => model.Owner) %>
<%= Html.EditorFor(model => model.Owner) %>
<%= Html.ValidationMessageFor(model => model.Owner)%>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
<div>
<%: Html.ActionLink("Back to List", "Index") %>
</div>
And have used Data Annotations:
[DataType(DataType.Text)]
[DisplayName("Owner")]
[Required]
[StringLength(60)]
public string Owner { get; set; }
I'm also using Entity Framwork 4.0.
Does anyone have any idea why my page is still posting back?
Many Thanks
开发者_Python百科Ted
This is consistent with behavior I've been getting in ASP.NET MVC since I started using it over a year ago. I haven't actually tried the RTM of 2.0, but I'm hearing that it's the same there as well- the client side validation emitting just doesn't work.
This thread here addresses the issue, and suggests you get the scripts from MVC Futures, which I've also seen before.
This link might also help: Link
That link above leads to an article that suggests you use the CDN versions of the scripts. I haven't tried that yet- it might work better because you're guaranteed to get a current, supported script.
精彩评论