我希望用ajax发送表单(对象列表)。但是JS中的函数serialize()并没有在控制器中读取
JS文件:
function save() {
$.ajax({
url: "/Ocena/AddOcene",
method: "POST",
dataType: "html",
data: {
id: $("#KlasaDDL option:selected").val(),
dodaj: $('#formOceny').serializeArray()
},
success: function (html) {
$('#load').html(html);
}
})
}
$(function () {
var llBtn = $('#saveForm');
llBtn.click(function () {
save();
});
});
在控制器中我有参数:
public ActionResult AddOcene(string id, List<Dodaj_ocene> dodaj)
查看:
@model List<biblioteka.Dodaj_ocene>
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "formOceny" }))
{
@Html.DropDownListFor(x => Model[0].Przedmiot, (SelectList)ViewBag.Przedmiot, "--Dostępne przedmioty--", new { @class = "form-control" })
@*@Html.DropDownList(m => Model[0].Przedmiot, *@
<p>Wprowadź rodzaj</p>
@Html.TextBoxFor(m => Model[0].Rodzaj, new { @class = "form-control" })
<p>Wprowadź Opis</p>
@Html.TextBoxFor(m => Model[0].Opis, new { @class = "form-control" })
<p>Wybierz wagę ocen:</p>
@Html.DropDownListFor(m => Model[0].Waga, new SelectListItem[] {
new SelectListItem{ Value = "5", Text = "V", Selected = Model[0].Waga == 5 } ,
new SelectListItem{ Value = "4", Text = "IV", Selected = Model[0].Waga == 4 } ,
new SelectListItem{ Value = "3", Text = "III" , Selected =
}, new { @class = "form-control" })
<br /> <br />
<table class="table">
<tr>
</tr>
@for (var index = 0; index < Model.Count; index++)
{
<tr>
<td>@Model[index].ImieNazwisko </td>
<td>
@Html.DropDownListFor(m => Model[index].Wartosc, new SelectListItem[]{
new SelectListItem{ Value = "0", Text = "Brak oceny", Selected = Model[index].Wartosc == 0 } ,
new SelectListItem{ Value = "1", Text = "1" , Selected = Model[index].Wartosc == 1 }
} , new { @class = "form-control" })
</td>
</tr>
}
</table>
<div class="form-group">
<div></div>
<button type="button" class="btn btn-info" id="saveForm">Zapisz</button>
</div>
}
我非常感谢一个显然