asp.net mvc 4 - Model binding validation errors -


In my custom model verification, I have the following:

  Public override object bind modal (Controller contact controller console, ModelBindingContext binding content) {var repository = Dependency Resolver Present. GETService (IContactRepository); IContactRepository repo = Repository as IContactRepository; USRContact c = repo.GetContactByID (Convert.ToInt64 (Binding Content. Value Provider .Gate Value ("Contact ID"). Attempted Value)); C.FormalName = bindingContext.ValueProvider.GetValue ("formal name"). Attempts value; If (repo.IsValidFormalName (c.ContactID, c.FormalName)) {var results = binding contentbox. ValuProvider.GetValue (Compulsive Contintbox. ModelName); Binding Contest.ModelState Adoldmodel ("formal name", resources. Errors.formalnamename Yuan); Return Binding Consultant Model; } CpreredName = bindingContext.ValueProvider.GetValue ("preferred name"). Attempts value; C. Alias ​​= binding content box. Value provider Gate value ("nickname"). C. Pseudo-name = binding contentbox. Value provider Gate value ("pseudonym"). Attempts value; C.GenderID = Convert.Tint32 (Binding Contact Value Value. Gate Value ("Gender ID"). Attempted Value); C.NationalityID = Convert. ToInt32 (Binding Containing Box Value Value. ("Nationality ID"). Attempted Value); C.ModifiedByID = Utilities SessionUtil.Current.UserID; C.ModifiedDate = DateTime.Now;   

}

My administrator calls the binder of this model by doing the following:

  public action update update ([Models Binder (ContactBilderContactModelBinder))] Contact USR.USRContact {if (ModelState.IsValid) {repository.Update (); Return View ("~ / view / share / contact / showContactInfo.cshtml", repository. GetContactByID ( Contact.ContactID);}}   

}

In my view-modell it is to say that a formal name is required and the alias must be less than 60 characters. If the model bind Have it constantly converted into a data model (USRC connect) and in my view if the View Module is expected, how do I display the errors?

Is there any way to make sure that the visual model But on verification errors, the controller can not constantly change the data model? Even if we check all model errors in the data object and validation errors Searches not, we users how to send them back to the scene, they only sent them with errors in the next Patbaks, involving them error.

Thanks for the help! I think the problem you are facing is that once you press those values ​​in another object custom binding machine they are no more as they were on the page.

A property called "Property Value" with HTML. Vality.For (x = & gt; x.PropertyValue) is going to look in the ModelState error collection for items with propertyValue.

Once you put those people in contact, then there is value contact. Property Value If you have approved this, then it will be added to the ModelState as "Contact Property Value". This will be picked up only by HTML. For validity (x => x.Contact.PropertyValue)

The easiest solution is to ensure that your input and output are followed by the same structure if you have the item Html.TextBoxFor ( X = & gt; x.Contact.SomeProperty), then things will get better.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -