如何将对象列表传递给控制器,我尝试了以下步骤,列表未通过。请参阅以下代码&建议我。
SupplimentDBQConfirmation ajax调用带来模型弹出并通过局部视图填充数据。 当我点击继续按钮我想将表集合传递给控制器,但我得到 dbqForm.SupplimentalDBQList 是零计数。如何克服这个问题?
型号:
public class SupplimentalDBQ
{
public string DBQName { get; set; }
public bool Checked { get; set; }
public string DBQDescription { get; set; }
public bool FillExamNow { get; set; }
public string FillExamNowId { get; set; }
public string DBQNameId { get; set; }
public string DBQDescriptionId { get; set; }
}
public class DBQ
{
public DBQ()
{
SupplimentalDBQList = new List<SupplimentalDBQ>();
}
public string documentId { get; set; }
...
...
public List<SupplimentalDBQ> SupplimentalDBQList { get; set; }
}
使用Javascript:
function SupplimentDBQConfirmation(section, auditHistory, callback) {
var ccDbqDtMoMappingId = $("#ccDbqDtMoMappingId").val();
var DBQType = $("#DBQType").val();
var documentId = $("#documentId").val();
var examinerId = $("#examinerId").val();
var dbqNumber = $("#dbqNumber").val();
var appointmentId = $("#appointmentId").val();
var Url = "/DBQ/SupplimentalDBQ?dbqNumber=" + dbqNumber + "&ccDbqDtMoMappingId=" + ccDbqDtMoMappingId + "&DbqType=" + DBQType + "&documentId=" + documentId + "&examinerId=" + examinerId + "&appointmentId=" + appointmentId;
$.ajax({
url: Url,
type: 'post',
success: function (result, status) {
debugger;
//alert(result + ' data ' + result.data);
$("#SupplimentalDbq_Content").html(result);
callback(result, status, section, auditHistory);
},
error: function (jqXHR, textStatus, errorThrown) {
$('#getCode').html('Error in SupplimentDBQConfirmation ajax call:' + textStatus + ' - ' + errorThrown);
$('#myAlertModal').modal({
});
}
});
}
function CreateAppointment() {
var infoForm = $("#SuppDBQform");
var CaseHeaderId = $('#CaseHeaderId').val();
var Url = '/DBQ/CreateSupplimentalDBQ';
$.ajax({
url: '@Url.Action("CreateSupplimentalDBQ", "DBQ")',
type: 'post',
data: infoForm.serialize() + "&CaseHeaderId=" + CaseHeaderId,
success: function (result) {
alert('status ' + ' ' + result);
},
error: function (jqXHR, textStatus, errorThrown) {
$('#getCode').html('Error in CreateAppointment ajax call:' + textStatus + ' - ' + errorThrown);
$('#myAlertModal').modal({
});
}
});
}
控制器:
public PartialViewResult SupplimentalDBQ(string dbqNumber, int ccDbqDtMoMappingId, string DbqType, string documentId, string examinerId, int appointmentId)
{
DBQ _dbq = new DBQ();
_dbq.dbqNumber = dbqNumber; _dbq.ccDbqDtMoMappingId = ccDbqDtMoMappingId; _dbq.DBQType = DbqType; _dbq.documentId = documentId; _dbq.appointmentId = appointmentId;
var AllDbq = new List<DbqMaster>();
var routingInformation = RestUtility.CreateRoutingInformation("provider", "dbq", "GetAllDBQ");
AllDbq = base.PerformGet<List<DbqMaster>>(routingInformation);
if (DbqType == "DBQHIVRelatedIllnesses")
{
var ldbqform = (DBQHIVRelatedIllnesses) MDESession.Current.DBQFORM;
int i = 1;
foreach(SupplimentalDBQ sdbq in ldbqform.SupplimentalDBQList)
{
sdbq.DBQDescription = AllDbq.Where(x => x.DbqNumber == sdbq.DBQName).FirstOrDefault().Description;
sdbq.FillExamNowId = "FillExam" + i.ToString();
sdbq.DBQNameId = "DBQName" + i.ToString();
sdbq.DBQDescriptionId = "DBQDescription" + i.ToString();
_dbq.SupplimentalDBQList.Add(sdbq);
i = i + 1;
}
}
return PartialView("~/Views/Examiner/SupplimentalDBQ.cshtml", _dbq);
}
[HttpPost]
public ActionResult CreateSupplimentalDBQ(DBQ dbqForm, string CaseHeaderId)
{
foreach(SupplimentalDBQ sdbq in dbqForm.SupplimentalDBQList)
{
CaseDetailsController obj = new CaseDetailsController();
var result = obj.SaveSelectedClaim(Convert.ToInt32(CaseHeaderId), false, sdbq.DBQName, "Added through supplimental dbq", dbqForm.ccDbqDtMoMappingId);
}
return Json("Data Saved Successfully");
}
查看:
@model VAMDEScheduler.General.DBQ
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "SuppDBQform" }))
{
@Html.AntiForgeryToken()
@Html.TextBoxFor(model => model.documentId)
@Html.TextBoxFor(model => model.ccDbqDtMoMappingId)
@Html.TextBoxFor(model => model.appointmentId)
@Html.TextBoxFor(model => model.DBQType)
@Html.TextBoxFor(model => model.dbqNumber)
<table class="table table-striped" border="0">
<thead>
<tr>
<th width="10%">
Fill Exam Now
</th>
<th width="15%">
DBQ Number
</th>
<th>
DBQ Description
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.SupplimentalDBQList)
{
<tr>
<td>
@Html.CheckBoxFor(modelItem => item.FillExamNow, new { id = item.FillExamNowId, name = item.FillExamNowId })
</td>
<td>
@Html.TextBoxFor(modelItem => item.DBQName, new { disabled = "disabled", id = item.DBQNameId, name = item.DBQNameId })
</td>
<td>
@Html.TextBoxFor(modelItem => item.DBQDescription, new { disabled = "disabled", id = item.DBQDescriptionId, name = item.DBQDescriptionId })
</td>
</tr>
}
</tbody>
</table>
}