c# - How do I change a value in the ModelState, so that it will be valid, using ASP.NET MVC? -
i allowing selectlist have initial value of "". user can choose whether fill in option or leave on default value.
this selectlist works on id, id passed controller. however, int not being selected, modelstate results in false input empty string rather int.
i want change value of empty string 0. result in modelstate being true. have been looking @ modelstate dictionary class, can change key, value pair before modelstate checked. however, have been unable use successfully.
https://msdn.microsoft.com/en-us/library/system.web.mvc.modelstatedictionary(v=vs.118).aspx
any appreciated.
try using
modelstate.setmodelvalue("propertyid", new valueproviderresult("new value", "", cultureinfo.invariantculture));
here usefull article.
Comments
Post a Comment