asp.net-mvc-2-validation

Server side validation in asp mvc 2, can the error message be moved to the vew?

I've just started getting into validation in asp mvc 2, and so far have been implementing server side validation through the System.ComponentModel.DataAnnotations attributes in the model. I agree, the correct place to put constraints is in the model, but is there any way to move the actual error messages into the view instead? ...

MVC Model Validation Programmatic Registration support

Today (15th Jan 2010) Scott blogged about the ASP.NET MVC2 model-validation http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx Anyone knows how can someone add validation rules at runtime programmatically ? "Programmatic Registration" is a similar functionality supported by ValidationAspects // regi...

ASP.Net MVC 2 RC: How To Use Client Validation with Data Annotations for Lists?

My problem: I can't get Data Annotations Client Validation to work with a List in my viewdata class. The skinny: In my view data class I have a List. public class FriendsViewData { public List<Person> people { get; set; } } I have all the properties of the class Person as required using Data Annotations. public class Person ...

Mvc2 validation summary and required metadata

source code... Thing is, if i specify required metadata using fluent modelmetadata provider like this=> public class Foo { public string Bar { get; set; } } public class FooModelMetadataConfiguration : ModelMetadataConfiguration<Foo> { public FooModelMetadataConfiguration() { Configu...

ASP.NET MVC 2 RC 2 "Wizard" for whole model validation

There is a good simple solution for a multi-page "Wizard" control in MVC here: http://www.highoncoding.com/Articles/647_Creating_Wizard_Using_ASP_NET_MVC_Part_1.aspx http://www.highoncoding.com/Articles/652_Creating_Wizard_in_ASP_NET_MVC_Part_2.aspx The model is populated in several steps and a hidden field is used to persist data bet...

How can I validate a multiselect in MVC2 form?

This seems like a really basic scenario, but I think it doesn't have a happy ending. I have a simple project class: public class Project { [Required(ErrorMessage = "Project title is required")] [DisplayName("Project Title")] public string Title { get; set; } [DisplayName("Related Categories")] public Category Cat...

Generating Data Annotations from Generated Classes

I have a linq to sql object or if neccessary Entity Framework object. I want to do MVC 2 Data Annotations for them, but I am endlessly lazy. Is there a way to automatically generate the data annotations a-la [Bind(Include = "Title,Description,EventDate,Address,Country,ContactPhone,Latitude,Longitude")] [MetadataType(typeof(Dinner_Val...

ASP.NET MVC 2 client-side validation rules not being created

MVC isn't generating the client-side validation rules for my viewmodel. The HTML just contains this: <script type="text/javascript"> //<![CDATA[ if (!window.mvcClientValidationMetadata) { window.mvcClientValidationMetadata = []; } window.mvcClientValidationMetadata.push({"Fields":[],"FormId":"form0","ReplaceValidationSummary":false}); ...

Globalization for ASP.NET MVC 2 Validators

Is there anyway to override the custom validation error messages from the ValidationAttributes? Basically I need the ValidationAttributes to support globalization. ...

ASP.NET MVC 2 RTM - Multiple-attribute validation with localization using data annotation fails

My resource file is working fine and the two keys (ValNameRequired and ValNameLength) are defined in the resource file. But when you have more than one attribute with localization, then the validation does not work. Anyone with a solution? public class ContactModel { [Required(ErrorMessageResourceType = typeof(ViewRes.Contact), Erro...

ASP.NET MVC 2 JQuery POST not displaying the model state errors

Hello, I have been using asp.net mvc for a bit (but I'm still a beginer). I want to have the ability to update two views as a result of a jquery postback. Basically I have a list and a details view. The details view is presented using a jquery popup (using jquery-UI popup). I only want to update the list if the details save is suc...

ASP.MVC 2 RTM + ModelState Error at Id property

I have this classes: public class GroupMetadata { [HiddenInput(DisplayValue = false)] public int Id { get; set; } [Required] public string Name { get; set; } } [MetadataType(typeof(GrupoMetadata))] public partial class Group { public virtual int Id { get; set; } public virtual string Name { get; set; } } And ...

Client-side validation with a model-less view in ASP.NET MVC 2

I'd like to use the new client side validation features in MVC 2 but I have a particular view that just has a couple textboxes on it and I don't want to create a strongly typed model for it. Can someone describe how to leverage the validation goodness in MVC 2 w/o a strongly typed model? ...

MVC: On partial page start validation from JS without postback

How do I start validation from the client/javascript using the MS MVC Validation library? Using MS ASP.Net MVC, I have a page with a PartialView in a modal dialog (change password). When the user selects 'save', I need to validate this on the client side without a full page postback. I am able in JS to post and refresh the partialVi...

Dyanamic client side validation

Is anyone doing dyanamic client validation and if so how are you doing it. I have a view where client side validation is enabled through jquery validator ( see below) <script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script> <script src="../../Scripts/jquery.validate.js" type="text/javascript"></script> ...

ASP MVC2 model binding issue on POST with strongly-typed HTML helpers

So I'm looking at moving from MVC 1.0 to MVC 2.0 RTM. One of the conventions I'd like to start following is using the strongly-typed HTML helpers for generating controls like text boxes. However, it looks like it won't be an easy jump. I tried migrating my first form, replacing lines like this: <%= Html.TextBox("FirstName", Model.Dat...

ASP.NET MVC 2.0 Validation and ErrorMessages

I need to set the ErrorMessage property of the DataAnnotation's validation attribute in MVC 2.0. For example I should be able to pass an ID instead of the actual error message for the Model property, for example... [StringLength(2, ErrorMessage = "EmailContentID")] [DataType(DataType.EmailAddress)] public string Email { get; s...

MVC2 ValidationSummary and Client side Validation

Hi I want to have the ValidationSummary errors displayed during Client Side validation. Currently the validation messages are only appears next to the field during client side validation. I use…. MicrosoftAjax.js MicrosoftMvcAjax.js MicrosoftMvcValidation.js as my client side libraries. There is a solution for jQuery Validation Lib...

ASP.NET MVC 2 "value" in IsValid override in DataAnnotation attribute passed is null, when incorrect date is submitted.

Hello to all! This is my first question here on stack overflow. i need help on a problem i encountered during an ASP.NET MVC2 project i am currently working on. I should note that I'm relatively new to MVC design, so pls bear my ignorance. Here goes : I have a regular form on which various details about a person are shown. One of them is...

ASPNET MVC - Why is ModelState.IsValid false "The x field is required" when that field does have a value?

I have a model like this: public PurchaseOrder { [Required] [StringLength(15)] public virtual string OrderNumber {get;set;} // etc. } When I submit an order from the view (using $.post, not input type=submit) it goes to my controller class: public class PurchaseOrderController { public JsonResult Save(Purchas...