javascript - Getting data from jquery dialog via ajax mvc -


have done lot of searching, , not sure why not working. have jquery dialog in displaying partial view. when pass data controller, shows blank model.

controller:

    public actionresult addingredient()     {         return partialview();     }      public jsonresult addingredientjson(ingredient model)     {         ingredient newingredient = model;          return json(null);     } 

partial view:

     <form id="addingredientform" class="addingredientform">          <div class="logincontent">               <label>name:</label>               @html.textboxfor(x => x.name, new { @class = "logintextbox" })          </div>          <div class="logincontent">               <label>category:</label>               @html.enumdropdownlistfor(x => x.category, new { @class = "logintextbox" })          </div>      </form> 

script:

$(document).ready(function () {     function addingredient() {         $.ajax({             url: "addingredientjson",             data: $('#addingredientform').serialize(),             type: "post"         });     }      $(function () {         $('#modaldialog').dialog({             autoopen: false,             width: 400,             resizable: false,             modal: true,             buttons: {                 "save": function () {                     addingredient();                 },                 cancel: function () {                     $(this).dialog("close");                 }             }         });           $('#opendialog').click(function () {             $('#modaldialog').load("@url.action("addingredient")", function () {                 $(this).dialog('open');             });             return false;         });      }); }); 

i have tried hardcoding in data script, , not passed either.

thanks help.

javascript case sensitive need more careful when using wordcase on object properties should lowercase

$.ajax({     url: "addingredientjson",     data: $('#addingredientform').serialize(),     type: "post" }); 

should be

$.ajax({     url: "addingredientjson",     data: $('#addingredientform').serialize(),     type: "post" }); 

also it's not idea use ajax without success , error handlers. request fail , user never know


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -