Advertisement
Guest User

Untitled

a guest
Sep 13th, 2015
245
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. You need to add the annotation `[HttpPost]` to your Action and change the return type to `JsonResult`..
  2.  
  3.     public class WorkingController : Controller
  4.     {
  5.         // GET: Working
  6.         public ActionResult Index()
  7.         {
  8.             return View();
  9.         }
  10.  
  11.         [HttpPost]
  12.         public JsonResult Save(WorkingModel model)
  13.         {
  14.             // All model properties are null here????
  15.  
  16.             return Json("Success");
  17.         }
  18.     }
  19.  
  20. For more info have a look here: http://www.dontpaniclabs.com/blog/post/2013/02/27/posting-json-data-to-an-mvc-controller-via-ajax/
  21.  
  22. EDIT:
  23.  
  24. If you still are getting nulls inside of Save, change to:
  25.  
  26.     public class WorkingController : Controller
  27.         {
  28.             // GET: Working
  29.             public ActionResult Index()
  30.             {
  31.                 return View();
  32.             }
  33.    
  34.             [HttpPost]
  35.             public JsonResult Save([FromBody]WorkingModel model)
  36.             {
  37.                 // All model properties are null here????
  38.    
  39.                 return Json("Success");
  40.             }
  41.         }
  42.  
  43. Sorry I can't fully remember when you have to use From Body and when you don't have to use, so try the first code first then try this
  44.  
  45. EDIT:
  46.  
  47. Also look into what `JSON.stringify` is producing... maybe its failing and sending null up.
  48.  
  49. EDIT 2:
Advertisement
RAW Paste Data Copied
Advertisement