json - Posting model from MVC to action using jquery post -


I am trying to post my model in an MVC action, using jquery post. In MVC, I am doing the following to serialize my model JSON:

MVC:

  & lt; Div class = "myModel" hidden = "true" & gt; @ Html.Raw (Json.Encode (model)) & lt; / Div & gt;  

Javascript:

  $ (".confirm_yes"). Click (function (e) {e.preventDefault (); // credit card session id var sessionid = $ (this) .Parent (). Find (". Payu_creditcard_sessionid"). Text (); var myModel = $ (" MyModel "). Text (); $ .post (" / Payuwalletlink / removecreditcard ", {model: myModel}, function (data) {/> whatever is with the returned view.});});  

Administrators :

  [HTTP post] Remove public proceedings Credit card (credit card model model) {Return (" PayUwallet "); }  

But I get the following error from my browser:

Failed to load the resource: the server with the status of 500 (internal server error) Answer:

What you're doing does not make sense to you a model Why will we pass in and then it will not completely unchanged? However, if necessary, the way to do this is to convert the model to a JavaScript object and post it back.

  var myModel = JSON.parse ('@ html.raw (json. Encode (ideal)) '); $ (".confirm_yes"). Click (function (e) {e.preventDefault (); // credit card session id var sessionid = $ (this) .Parent (). (". Payu_creditcard_sessionid").); $ Post ('@ Url.Action ("removecreditcard", "payuwalletlink")', mymold, function (data) {....});});  

Not sure that var sessionid = .. is for (you do not use it).

I suspect that your post is trying to delete an object on the method, in that case, pass the object's id back.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -