Ho la seguente classe di javascript che sto cercando di passare a un ASP.NET MVC controllerPassando serie Javascript per ASP.NET MVC controller
var postParams = {
attributes : [
{
name : '',
description: '',
attributeType : '',
value : ''
}
]
};
postParams.attributes[0] = new Object();
postParams.attributes[0].name = "test";
postParams.attributes[0].description = "test";
postParams.attributes[0].attributeType = "test";
postParams.attributes[0].value = "test";
Ecco come chiamo il metodo di controllo:
var actionURL = "@Url.Action("Save", "Catalog")";
$.ajax({
type: "POST",
url: actionURL,
data: postParams ......
Sul lato controller che ho dichiarato un ViewModel come segue:
public class AttributeViewModel
{
public string name { get; set; }
public string description { get; set; }
public string attributeType { get; set; }
public string value { get; set; }
}
mio controller Salva metodo è de clared come segue:
public JsonResult Save(AttributeViewModel[] attributes)
Quando eseguo il valore di attributi è sempre nullo.
Qualche idea? Non sai come iniziare a eseguire il debug di questo.
Grazie per il suggerimento. Aggiunto un riferimento a Json.net e aggiunto il filtro ma null è ancora passato agli attributi. – Lance
@Lance Risposta aggiornata con il codice cliente –
Grazie Sanja, l'aggiunta di JSON.stringify() ha funzionato bene! – Lance