My current code looks like the following. How can I pass my array to the controller and what kind of parameters must my controller action accept?
function getplaceholders() { var placeholders = $('.ui-sortable'); var result = new Array(); placeholders.each(function() { var ph = $(this).attr('id'); var sections = $(this).find('.sort'); var section; sections.each(function(i, item) { var sid = $(item).attr('id'); result.push({ 'SectionId': sid, 'Placeholder': ph, 'Position': i }); }); }); alert(result.toString()); $.post( '/portal/Designer.mvc/SaveOrUpdate', result, function(data) { alert(data.Result); }, 'json'); };
My controller action method looks like
public JsonResult SaveOrUpdate(IList<PageDesignWidget> widgets)
I’ve found an solution. I use an solution of Steve Gentile, jQuery and ASP.NET MVC – sending JSON to an Action – Revisited.
My ASP.NET MVC view code looks like:
and my controller action is decorated with an custom attribute
Code for the custom attribute can be found here (the link is broken now).
Because the link is broken this is the code for the JsonFilterAttribute
JsonConvert.DeserializeObject is from Json.NET
Link: Serializing and Deserializing JSON with Json.NET