json - Passing model from view to vontroller via Jquery ajax -
i'm trying pass json data view controller reason not wanting work. when debug controller, model showing null , life of me cannot figure out why.
here's controller:
public jsonresult updatevideourl(list<geturldata> model) { //var updateurls = new appservices.video.updateallvideo(); //var loginvideourl = model.tostring(); //dynamic update = updateurls.execute(model); return json(model); }
my view:
$('#btnupdate').click(function (e) { //debugger; var model = { 'model.loginfiles.englishvideourl': $("#loginenvideoinput").val(), 'model.loginfiles.spanishvideourl': $("#loginesvideoinput").val(), 'model.welcomefiles.englishvideourl': $("#welcomeenvideoinput").val(), 'model.welcomefiles.spanishvideourl': $("#welcomeesvideoinput").val(), 'model.benefitfiles.englishvideourl': $("#benefitenvideoinput").val(), 'model.benefitfiles.englishvideourl': $("#benefitesvideoinput").val(), 'model.myenrollmentfiles.englishvideourl': $("#myenrollmentenvideoinput").val(), 'model.myenrollmentfiles.englishvideourl': $("#myenrollmentesvideoinput").val(), 'model.adminsidefiles.englishvideourl': $("#adminsideenvideoinput").val(), 'model.adminsidefiles.englishvideourl': $("#adminsideesvideoinput").val() } $.ajax({ type: "post", url: '@url.action("updatevideourl", "managevideos")', data: json.stringify(model), contenttype: 'application/json; charset=utf-8', //async: true, success: function (model) { //return model }, error: function (jqxhr, errorthrown, errorthrown) { console.log("there error on post: " + " " + errorthrown + "." + " please see above if applicable"); } }); });
and model:
public class applicationvideomodel { public list<geturldata> geturldata { get; set; } } public class geturldata { public geturldata(string englishurl, string spanishurl) { englishvideourl = englishurl; spanishvideourl = spanishurl; } public string englishvideourl { get; set; } public string spanishvideourl { get; set; } }
what overlooking here?
model comes null because convert one object , not list of objects.
if change parameter in post method to:
public jsonresult updatevideourl(geturldata model) { return json(model); }
then model won't null.
if need send list parameter, have stringify array of objects this:
var model = [{ 'model.loginfiles.englishvideourl': $("#loginenvideoinput").val(), next properties }, { second object }]
Comments
Post a Comment