views:

78

answers:

0

I have an object named User, with a property Name, with a Required attribute.

public class User
{
     public int Id { get; set; }

     [Required]
     public string Name { get; set; }
}

I have created a textbox, like so:

<%= Html.TextBoxFor(model => model.Name) %>

When enabling clientside validation, Name is perfectly validated client side.

However, if I create a ViewModel where User is now a property

public class UserModel
{
     public User TheUser { get; set; }
     public string SomeOtherProperty { get; set; }
}

and create my textbox

<%= Html.TextBoxFor(model => model.TheUser.Name) %>

then clientside validation fails. The form is posted without client validation picking up the error.

It looks like the javascript window.mvcClientValidationMetadata gets filled up as before, with no noticeable difference.

What gives? Is there something i need to do?

I'm using

  • ASP.NET MVC 2 RC2 (with .NET 3.5/VS2008)
  • MicrosoftMvcJQueryValidation.js from the latest Futures download

Edit:

Upon closer inspection window.mvcClientValidationMetadata isn't filled up as it should. No ValidationRules are specified:

{"FieldName":"TheUser.Name","ReplaceValidationMessageContents":true,"ValidationMessageId":"TheUser_Name_validationMessage","ValidationRules":[]}