【发布时间】:2015-03-09 15:39:02
【问题描述】:
我正在用 JQUERY 之类的方式创建表单输入字段
$('#students').live('change', function () {
var value = $(this).val();
if (value) {
$.ajax({
type: "GET",
timeout: 10000,
url: "@Url.Action(MVC.Company.ManageWorkReport.GetStudent())",
data: { studentId: value },
cache: false,
success: function (data) {
if (data) {
$("#students tbody").html(data);
}
},
error: function (xhr, status, error) {
alert(xhr.responseText);
}
});
}
return false;
});
插入数据的HTML代码是
@using (Html.BeginDefaultForm(MVC.Company.ManageWorkReport.Create()))
{
<table class="table table-striped table-bordered bootstrap-datatable datatable" id="students">
<thead>
<tr>
<th>Ime in Priimek</th>
<th>Vrsta</th>
<th>Začetek dela</th>
<th>Konec dela</th>
<th>Enota</th>
<th>Cena za enoto</th>
<th>Količina</th>
<th>Neto znesek</th>
<th>Bruto znesek</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="11">Podatek še ne obstaja</td>
</tr>
</tbody>
</table>
@Html.SimpleSubmitAndCancelButton(Translations.Global.SAVE, Translations.Global.CANCEL)
}
和 C#
[HttpGet]
public virtual PartialViewResult GetStudent(int studentId)
{
StudentsWorksReportsFormModel studentsWorksReportsFormModel = new StudentsWorksReportsFormModel();
.....
var view = PartialView("StudentWorkReportResult", studentsWorksReportsFormModel);
return view;
}
问题是当我在表单中输入数据并单击提交按钮时,模型始终为空。如果我用 JQUERY 填充页面然后在文本字段中输入数据,为什么模型是空的?如何填充模型,我可以在数据库中插入数据。
【问题讨论】:
标签: javascript c# jquery asp.net-mvc asp.net-mvc-4