我是MVC的初学者,并尝试将集合发布到控制器操作,但在控制器中,它显示集合的计数= 0。我尝试了很多不同的方法但没有成功。
我有两个视图模型(PatientViewModel,PatientTestViewModel)和内部患者视图模型,我有一个名为PatientTestVM的PatientTestViewModel集合。下面是代码...
public class PatientViewModel
{
private MHUContext ctx = new MHUContext();
public patient _Patient { get; set; }
public string MhuKey { get; set; }
public lkp_child _LkpOccupation { get; set; }
public List<PatientTestViewModel> PatientTestVM { get; set; }
}
并且有一个名为Patient.cshtml的
的PatientViewModel视图@using Shared
@model Shared.PatientViewModel
@{
ViewBag.Title = "Patient";
}
<section class="well">
@using (Html.BeginForm("CreatePatient", "Patients", FormMethod.Post, new { id = "patient-main-form" }))//new { ReturnUrl = ViewBag.ReturnUrl }))
{
...一些代码,然后我调用部分视图来呈现PatientTestViewModel的集合
<div class="accordion panel-group" id="accordion-pat-mh">
<div class="accordion-group panel panel-primary">
<div class="accordion-heading panel-heading">
<h3 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion-pat-mh" href="#mh">Medical History</a>
</h3>
</div>
<div id="mh" class="accordion-body panel-body collapse in">
<div class="accordion-inner ">
@for (int i = 0; i < Model._PatientTestVM.Count; i++)
{
Html.RenderPartial("_PatientTestTile", Model._PatientTestVM[i]);
}
</div>
</div>
</div>
</div>
}
这是局部视图
@model Shared.PatientTestViewModel
<div>
<div class="col-sm-12 div_@(Model.PatientTestKey)">
<div class=" form-horizontal form-widgets col-sm-2">
<div class="form-group">
<label style="font-weight:normal; text-align:center;" class="control-label col-sm-10 col-md-8" for="">@Model._PatientTest.lkp_child.name</label>
</div>
</div>
<div class=" form-horizontal form-widgets col-sm-4">
<div class="form-group">
<label style="font-weight:normal; text-align:center;" class="control-label col-sm-10 col-md-8">@Model._PatientTest.date_created</label>
</div>
</div>
<div class=" form-horizontal form-widgets col-sm-3">
<div class="form-group">
<div class="col-sm-10 col-md-8">
<button type="button" class="k-button k-state-default btnEdit_@(Model.PatientTestKey)">Edit</button>
<button type="button" class="k-button k-state-default btnDelete_@(Model.PatientTestKey)">Delete</button>
</div>
</div>
</div>
<div class=" form-horizontal form-widgets col-sm-3">
<div class="form-group">
<div class="col-sm-10 col-md-8">
@Html.EditorFor(m => m._PatientTest.test_status)
<span> Result Received</span>
</div>
</div>
</div>
现在当我提交from时,它不会在patienttestviewmodel的集合中显示任何记录
public ActionResult CreatePatient(PatientViewModel PostedPatientVM)
{
if (ModelState.IsValid)
{
postedPatientVM.PatientTestVM.Count = 0
有关此计数为零的任何帮助/建议?请注意这是编辑记录的情况(我收集了数据,但回发时,收集中的数据变为空)