Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Give all your checkboxes a fixed name, like GenreIds.</p> <p>Then, in your action you should receive a <code>string[] genreIds</code> parameter.</p> <p>When posting the form, the genreIds is posted as am array, so it must be received in an array parameter.</p> <p>If this doesn't work because you have many categories and want to receive each group of GenreIds in its own category, then you can send a JSON representation of the form values and receive and deserialize it on the server side. To do so:</p> <p>On the razor template:</p> <ol> <li>Use the name of the genre to name all the checkboxes in each category</li> </ol> <p>Handle the form sumit event, and:</p> <ol> <li>Use <a href="http://api.jquery.com/serializeArray/" rel="nofollow">jQuery serializeArray</a>, to put all the form elements in an array</li> <li>Then use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify" rel="nofollow">JSON.stringify</a> to convert this array to JSON format</li> <li>Finally copy this string to a hidden field with a fixed name and post the form. I.e. in a hidden field with the name "serializedFormValues"</li> </ol> <p>On the server side:</p> <ol> <li>Add a parameter to your action with the name "serializedFormValues", and type = string</li> <li>get the value of this parameter and deserialize the received JSON string, and use it on the server side</li> </ol> <p>If you use JSON.NET you can convert the <a href="http://james.newtonking.com/projects/json/help/index.html?topic=html/ConvertingJSONandXML.htm" rel="nofollow">JSON to XML</a>, or <a href="http://james.newtonking.com/projects/json/help/index.html?topic=html/DeserializeAnonymousType.htm" rel="nofollow">to an anonymous type object</a>. There are another posibilities.</p> <p>Remember that in any case, the genre Ids will always be <code>string[]</code> (or <code>int</code>, if ti's the case) and this arrays will only contain the checked values.</p> <p>There is a last posibility which is processing the <code>Request.Form</code> "manually". But this is harder to do.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    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