Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is working for me, I've left the original post below:</p> <pre><code>$.ajax({ type: 'POST', contentType: 'application/json', url: '@Url.Action("Contact", "Home")', data: JSON.stringify({ completionMessage: $("#CompletionMessage").val(), description: $("#Description").val(), clues: $("#Clues").val(), leaderboard: $("#Leaderboard").val(), treasureHuntId: $("#TreasureHuntId").val(), ids: positions }) }); </code></pre> <p>You need to remove the 'Model' from your Url.Action() and of course change the values from my sample to the action and controller name you are using. I've included the 'positions' variable just to make it clear, your value will come from outside of this closure.</p> <p>--- Original Answer ---</p> <p>You need to include all of the hidden values in the data that you pass for your AJAX call. What you have written is working as you have written it, but the additional form values from your page are not going to be included. If I had to guess, if the TreasureHuntId is an integer then it is populated with the first value in the array from the positions variable. What you might want to do is put Fiddler in and watch what is getting posted.</p> <p>Take a look at the source in the browser for your URL. It might surprise you on how that looks compared to what you are expecting. Are you depending on the default route for this? Check out if you've made any special route for this action in the controller.</p> <p>I think the best method is to create the object manually: jQuery documentation on AJAX specifies that the data setting is either a serialized query string or an object. If you use an object then you will likely want to change the dataType to 'json', you don't need a contentType.</p> <pre><code>data: { CompletionMessage: $('#CompletionMessage').val(), Description: $('#Description').val(), // other fields here... ids: JSON.stringify(positions) } </code></pre> <p>Note you may need/want to change the signature on the controller to accept individual parameters vs the TreasureHuntDetails class if it doesn't identify the method.</p> <p>Alternatively, take a look at the serialize() function in jQuery - the documentation on the <a href="http://api.jquery.com/jQuery.post/" rel="nofollow">$.post()</a> will help you toward a solution. Keep in mind if you go this route then you need to remote the contentType as it defaults to the correct form MIME type.</p>
    singulars
    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.
 

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