jquery - MVC 6 - cannot pass multiple JSON parameters to a controller anymore -


i have been working use new asp.net 5 system, , microsoft's asp.net mvc 6, finding few key problems preventing me going forward; notably cannot seem pass multiple json parameters through controller method anymore.

for example, have following controller method;

[httppost] [route("edit/profile")] public void attribute([frombody]models.profile model, bool editing) {     // ...     // model comes in null     // editing comes in default (false) } 

i attempting pass data controller using $.ajax.

$.ajax({     url: '/edit/profile',     type: 'post',     datatype: 'json',     contenttype: 'application/json',     data: json.stringify({ model: _this.model, editing: true }) }); 

but no matter do, parameters come in null on controller. have tried various things, , if ignore ({ model : _this.model ... }) part , pass in 1 parameter, comes through expected data: json.stringify(_this.model)

the model looks this; (obviously not final model, dummy while work on problem)

_this.model = {     id: null,     name: null     text: null }; 

and corresponds c# class;

namespace models {     public class profile {         public string id { get; set; }         public string name { get; set; }         public string text { get; set; }     } } 

i cannot figure out life of me. worked fine on mvc 5, since upgrading defunct.

i using jquery 2.1.4

i have similar problem. have solved using separate class data.

[httppost] [route("edit/profile")] public void attribute([frombody] profiledata data) {     var model = data.model;     var editing = data.editing; }  public class profiledata {     public models.profile model { get; set; }     public bool editing { get; set; } }  $.ajax({     url: '/edit/profile',     type: 'post',     datatype: 'json',     contenttype: 'application/json',     data: { data: { model: _this.model, editing: true } } }); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -