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

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

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -