I have a model I am passing to a view and using Html.Raw to encode it into a JSON object:
var model = @Html.Raw(Json.Encode(Model));
On the page I fill various portions of the model from fields in the page:
model.ProductId = $("#txtProductId").val();
and then try to post it to the controller that way with ajax:
$.ajax({
type: 'POST',
url: '@Utl.Action("AddProducts"),
data: JSON.stringify(model),
dataType: 'json',
//etc
but it is never making it to the controller method:
[HttpPost]
public ActionResult AddProducts(ProductModel, model)
{
//do stuff with the model data
}
Can anyone help me out here and explain how I have to changs things to get the model to post?
My models, simplified:
public class OrderModel {
public ProductModel Product {get;set;}
public PersonModel Person {get;set;}
public List<ProductModel> Products {get;set;}
}
public class ProductModel {
public string Partno {get;set;}
public int Quantity {get;set;}
/// etc
}
public class PersonModel {
public string Surname {get;set;}
public string GivenName {get;set;}
public string Address {get;set;}
/// etc
}