ajax - Can I post a JSON model from html.raw to controller? -
I have a model that I see and am using HTML. To encode it in a JSON object:
var model = @ html. Ro (jason. Encode (model)); On the page I fill out various parts of the model from page fields:
model.ProductId = $ ("#txtProductId"). Val (); and then try posting the controller on that path with AJAX:
$ .ajax ({type: 'POST', url : '@ Utl.Action ("AddProducts"), data: JSON.stringify (model), data type:' json ', // etc but it is never in the controlling method Creating: <
Can someone out of here and explain how it works? I have to change things to post a model. ?
My models, Simplified:
Public category model model {public product model product {get} set;} public-purpose person public sector producers (meet; set;}} public category product model {public string part {set; set;} public int Quantity {set; set;} /// etc} Public class person model {public string nickname {get; set;} public string GivenName {get; set;} public string addre ss {get; set;} /// etc} < / Code>
code you
$ Ajax ({type: 'POST', url: '@ Url.Action ("AddProducts"), Data: Model, // is not string data:' Jason ', .. .. < P> or $ .post ('@ Url.Action ("AddProducts"), model, function (data) {// do stuff with returned data}} will post back to
[HPPOST] public Actioners Edproducts (Product Model Admin) {// working with model data} Below the model in your view, ProductModel
However, if you posted the form back If you want to run, then you var model = $ ('Form'). Serialize (); instead of manually setting the properties of the object.
Comments
Post a Comment