Hi All
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
Ted