I'm working at an ASP.NET MVC website using C#.
On a page I try to send back a complete model to the controller. In this model most inputs are unique variables, and there is an array.
In the model, the array is defined like this:
public class SimulazioneModelComplete
...
public SoaValueModel[] GareSoaSec { get; set; }
The razor / html code (very simplified!) is like this
@model SimulazioneModelComplete
@using (Html.BeginForm("CreaEsito", "Simulazioni", FormMethod.Post, new { id = "CreaEsito", name = "CreaEsito", enctype = "multipart/form-data" }))
{
...
@foreach (SoaModel soa in ViewBag.Categorie)
<input type="checkbox" name="GareSoaSec[@counter].IdSoa" id="GareSoaSec[@counter].IdSoa" value="@soa.id" />
...
}
The user posts data clicking a button:
<button onclick="Save()">SAVE</button>
The onclick javascript is like this:
function Save()
{
$.post("/Abbonamenti/Simulazioni/CreaEsito", $("CreaEsito").serialize(), function (data) { });
};
The CreaEsito method is like this:
[HttpPost]
[AuthorizedOnly(Roles = "Administrator, Agent, Esiti")]
public ActionResult CreaEsito(SimulazioneModelComplete model, SoaValueModel[] GareSoaSec)
I try in a lot of ways, but I never have a complete model, with both the simple variables and the array of objects. It seems like the "link" made by "name" doesn't work properly, and I don't understand why.
It should work well (I do the same in other pages, and everything works well), but this time it doesn't work. When I look the model sent back to the controller, the unique variables are ok, the array is empty, length is zero.
I've lost all Friday and Saturday, now is 10PM and I'm still fighting, without any solution.
Can someone help?