Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Today I came up with a solution for a similar problem that could be perhaps be adapted to fit your particular need. It will "do the job" for what you are asking, but may not be the most reusable solution.</p> <p>The idea is that you will walk through the posted form fields and fix the "broken" checkbox values. You can create a ValueProviderDictionary a.k.a. IDictionary&lt;string, ValueProviderResult&gt; and then hand that to your UpdateModel method.</p> <pre><code>public static IDictionary&lt;string, ValueProviderResult&gt; CreateScrubbedValueProvider(NameValueCollection postedForm, string[] checkboxFieldsToScrub) { Dictionary&lt;string, ValueProviderResult&gt; dict = new Dictionary&lt;string, ValueProviderResult&gt;(); foreach (string key in postedForm.AllKeys) { string[] values = postedForm.GetValues(key); if (checkboxFieldsToScrub.Contains(key)) { // Ensure we have a "true" value instead of "Y" or "YES" or whatever... // Note that with a checkbox, only the first value matters, so we will only // worry about values[0] and not values[1] (the "unchecked" value, if exists). if (values[0] == "Y" || values[0] == "YES") { values[0] = "true"; } } string value = String.Join(",", values); ValueProviderResult vpr = new ValueProviderResult(values, value, null); dict.Add(key, vpr); } return dict; } </code></pre> <p>Your controller will need to accept a NameValueCollection (or FormCollection) in its parameters, and you'll need to hand your generated ("scrubbed") value provider dictionary to the UpdateModel method. I haven't tested this exactly, but my version of this is working very similarly for me. Best of luck!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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