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.

http://geekswithblogs.net/bobhardister/archive/2013/03/11/retain-and-set-posted-checkbox-value-in-the-mvc-4.aspx


Comments

Popular posts from this blog

asp.net mvc - Cannot display error message on Editor or EditorFor -

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Using str_replace to translate a MySQL Table in html -