Home MVC, Jquery and Ajax - JSON with null parameters in controller
Reply: 0

MVC, Jquery and Ajax - JSON with null parameters in controller

user937
1#
user937 Published in July 18, 2018, 12:38 am

I have a problem with passing object with properties into controller.
Both are always null.
In console.log passed data looks fine. Where I made a mistake?
I looked into other solutions and nothing pushed me to the correct way...

C#, MVC5, Jquery 2.1.1

Controller:

public class Position  
{  
string intnew { get; set; }  
string intlast { get; set; }  
}

Action:

 [HttpPost]
    public ActionResult change(Position position)
    {
    return Json(new { result = "" });
    }

And View:

var pos = new Object;
pos.intnew = '22';
pos.intlast = '11';

$.ajax({
url: '/szkolenia/change',
contentType: 'application/json; charset=utf-8',
datatype: 'json',
data: JSON.stringify({ position: pos }),
type: "POST",
success: function (_infoLogs) {
console.log(JSON.stringify({ position: pos }));
}
});
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.310254 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO