Ich bin nicht sicher, warum der Controller Daten von einem Ajax-Aufruf empfängt. Kann ich etwas falsch machen?Controller in meinem MVC-Projekt Null von Ajax Post-Anruf
[HttpPost]
[Route("Product/UpdateDetails")]
public ActionResult UpdateProduct (ProductModel model) <<// model here is null
{
Product p = new Product
{
ProductId = p.ProductId,
Price = p.Price,
};
return View("_ProductDetail"); }
Ajax-Aufruf unter:
var model = {
ProductId: 1,
Price: 270.99,
};
var json = JSON.stringify(model)
$.ajax({
url: '/Product/UpdateDetails',
type: 'Post',
contentType: "application/json; charset=utf-8",
model: model,
success: function (results) {
}
});
//Model
public class Product
{
public int Id {get;set;}
public double Price {get;set;}
}
Könnt ihr etwas erkennen, dass ich falsch oben im Code tun kann? Ich kann nichts sehen, was ich falsch mache.
Löschen Sie einfach 'contentType:" application/json; charset = utf-8 ",' und 'model: model,' und fügen Sie 'data: model' hinzu. (Es ist nicht notwendig, die Daten zu stringieren, aber Sie haben es trotzdem nicht benutzt) –