asp.net-mvc-2-validation

Generating Data Annotations from Generated Classes

蓝咒 提交于 2020-03-16 07:35:08
问题 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_Validation))] public partial class Dinner { public bool IsHostedBy(string userName) { return HostedBy.Equals(userName, StringComparison.InvariantCultureIgnoreCase);

Generating Data Annotations from Generated Classes

◇◆丶佛笑我妖孽 提交于 2020-03-16 07:34:51
问题 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_Validation))] public partial class Dinner { public bool IsHostedBy(string userName) { return HostedBy.Equals(userName, StringComparison.InvariantCultureIgnoreCase);

Generating Data Annotations from Generated Classes

你说的曾经没有我的故事 提交于 2020-03-16 07:34:05
问题 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_Validation))] public partial class Dinner { public bool IsHostedBy(string userName) { return HostedBy.Equals(userName, StringComparison.InvariantCultureIgnoreCase);

ASP.NET MVC 2 Model Errors with Custom Exceptions

*爱你&永不变心* 提交于 2019-12-24 00:34:22
问题 I have a custom exception class: public class MyException: Exception { public MyException(MyExceptionEnum myError) : base(myError.ToDescription()) { } public MyException(MyExceptionEnum myError, Exception innerException) : base(myError.ToDescription(), innerException) { } } .ToDescription is a extension method on MyExceptionEnum to provide enum-to-string mapping for the exception error details. Here's how i throw it: if (someCondition) throw new MyException(MyExceptionEnum.SomeError); So i

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

烈酒焚心 提交于 2019-12-21 21:52:52
问题 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}); //]]> </script> Note that Fields[] is empty! My view is strongly-typed and uses the new strongly-typed HTML helpers ( TextBoxFor() , etc). View Model / Domain

Is there a way to allow a user to submit html content while still enabling model validation?

蹲街弑〆低调 提交于 2019-12-11 02:13:40
问题 I need to allow users to submit a form value containing html in their text inputs. This is an internally-facing application so it's reasonably safe to do so. I have succesfully used the [ValidateInput(false)] attribute on the method in question, but this inhibits all model validation for the method/view model in question, but I only want to allow html in one of the TextBoxes and do not necessarily wish to write my own guard clauses for every other piece of model validation in the same method

Support for nested model and class validation with ASP.NET MVC 2.0

巧了我就是萌 提交于 2019-12-07 02:15:00
问题 I'm trying to validate a model containing other objects with validation rules using the System.ComponentModel.DataAnnotations attributes was hoping the default MVC implementation would suffice: var obj = js.Deserialize(json, objectInfo.ObjectType); if(!TryValidateModel(obj)) { // Handle failed model validation. } The object is composed of primitive types but also contains other classes which also use DataAnnotications. Like so: public class Entry { [Required] public Person Subscriber { get;

ASP.NET MVC: DropDownList validation

谁说胖子不能爱 提交于 2019-12-06 11:20:14
问题 Note: The following is just an example. I'm pretty new to ASP.NET MVC and I'm trying to get my head around how validation of dropdown lists work. I have the following property in my ProfileViewModel class: [DisplayName("Gender")] public bool? Gender { get; set; } null is meant to mean "unknown", true female and false male. In the view model constructor I AllGenders = new List<SelectListItem>(2) { new SelectListItem {Text = "Unknown", Value = "null"}, new SelectListItem {Text = "Male", Value =

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

允我心安 提交于 2019-12-04 14:52:45
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}); //]]> </script> Note that Fields[] is empty! My view is strongly-typed and uses the new strongly-typed HTML helpers ( TextBoxFor() , etc). View Model / Domain Model public class ItemFormViewModel { public Item Item { get; set; } [Required] [StringLength(100)]

How to display MVC 3 client side validation results in validation summary

谁说胖子不能爱 提交于 2019-12-03 11:37:58
问题 I have a registration form on which I use client side validation (Required, StringLength etc. specified on my view model). The form is currently pretty much how the scaffolder creates it: @using (Html.BeginForm("Index", "Registration")) { @Html.ValidationSummary(true) <fieldset> <legend>Registration details</legend> @Html.ValidationSummary(false, "Please correct these errors:") @Html.ValidationMessageFor(model => model.Username) <div class="editor-label"> @Html.LabelFor(model => model