Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found some insight here: <a href="http://forums.asp.net/p/1396019/3006051.aspx" rel="nofollow noreferrer">http://forums.asp.net/p/1396019/3006051.aspx</a></p> <blockquote> <p>If you don't want to use Builtin Model Binding, then to use Bultin Validation (SanjaySutar want to use), for every ModelError you add, you will need to add a ModelValue: ModelState.AddModelError("Name", "Bad Name");</p> <p>ModelState.SetModelValue("Name", ValueProvider["Name"]);</p> </blockquote> <p>So I updated my code like so:</p> <pre><code>ModelState.SetModelValue("Description", new ValueProviderResult(ValueProvider["Description"].AttemptedValue, collection["Description"], System.Globalization.CultureInfo.CurrentCulture)); ModelState.SetModelValue("EventName", new ValueProviderResult(ValueProvider["EventName"].AttemptedValue, collection["EventName"], System.Globalization.CultureInfo.CurrentCulture)); ModelState.SetModelValue("EndDate", new ValueProviderResult(ValueProvider["EndDate"].AttemptedValue, collection["EndDate"], System.Globalization.CultureInfo.CurrentCulture)); ModelState.SetModelValue("StartDate", new ValueProviderResult(ValueProvider["StartDate"].AttemptedValue, collection["StartDate"], System.Globalization.CultureInfo.CurrentCulture)); ModelState.SetModelValue("TrackId", new ValueProviderResult(ValueProvider["TrackId"].AttemptedValue, collection["TrackId"], System.Globalization.CultureInfo.CurrentCulture)); ModelState.SetModelValue("WebContent", new ValueProviderResult(ValueProvider["WebContent"].AttemptedValue, collection["WebContent"], System.Globalization.CultureInfo.CurrentCulture)); </code></pre> <p>The reason I am doing this is because I wanted to a. have all (or as much as possible) validation done in my Business Object, including required fields, and b. I wanted my own messages in the validation summary (e.g. "FieldX is a required field." instead of "A value is required."). If there's a better way to do this, please see my other question: <a href="https://stackoverflow.com/questions/646270/asp-net-mvc-custom-validation-message-for-value-types">ASP.NET MVC - Custom validation message for value types</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload