asp.net-mvc-validation

Manually invoking ModelState validation

馋奶兔 提交于 2019-11-27 21:46:17
I'm using ASP.NET MVC 3 code-first and I have added validation data annotations to my models. Here's an example model: public class Product { public int ProductId { get; set; } [Required(ErrorMessage = "Please enter a name")] public string Name { get; set; } [Required(ErrorMessage = "Please enter a description")] [DataType(DataType.MultilineText)] public string Description { get; set; } [Required(ErrorMessage = "Please provide a logo")] public string Logo { get; set; } } In my website I have a multi-step process to create a new product - step 1 you enter product details, step 2 other

MVC Razor Validation Errors showing on page load when no data has been posted

对着背影说爱祢 提交于 2019-11-27 03:11:39
问题 I'm messing around with data annotations. When I click on a link to go to a page, the validation messages are being displayed, but I would like to have the validation messages not show unless data has been posted. View: @Html.TextBoxFor(m => m.EmailAddress, new { @placeholder = "Enter Email", @class = "form-control" }) @Html.ValidationSummary(true, "Registration Failed. Check your credentials") @Html.ValidationMessageFor(m => m.EmailAddress, "You must enter a valid Email Address.") Model:

Manually invoking ModelState validation

亡梦爱人 提交于 2019-11-26 23:06:44
问题 I'm using ASP.NET MVC 3 code-first and I have added validation data annotations to my models. Here's an example model: public class Product { public int ProductId { get; set; } [Required(ErrorMessage = "Please enter a name")] public string Name { get; set; } [Required(ErrorMessage = "Please enter a description")] [DataType(DataType.MultilineText)] public string Description { get; set; } [Required(ErrorMessage = "Please provide a logo")] public string Logo { get; set; } } In my website I have

How to create custom validation attribute for MVC

≯℡__Kan透↙ 提交于 2019-11-26 18:54:12
I'd like to create a custom validation attribute for MVC2 for an email address that doesn't inherit from RegularExpressionAttribute but that can be used in client validation. Can anyone point me in the right direction? I tried something as simple as this: [AttributeUsage( AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false )] public class EmailAddressAttribute : RegularExpressionAttribute { public EmailAddressAttribute( ) : base( Validation.EmailAddressRegex ) { } } but it doesn't seem to work for the client. However, if I use RegularExpression(Validation

How to create custom validation attribute for MVC

馋奶兔 提交于 2019-11-26 06:40:04
问题 I\'d like to create a custom validation attribute for MVC2 for an email address that doesn\'t inherit from RegularExpressionAttribute but that can be used in client validation. Can anyone point me in the right direction? I tried something as simple as this: [AttributeUsage( AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false )] public class EmailAddressAttribute : RegularExpressionAttribute { public EmailAddressAttribute( ) : base( Validation.EmailAddressRegex ) { } }