Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法将收集数据发布到控制器操作_C#_Asp.net Mvc_Asp.net Mvc 4_Asp.net Mvc Controller - Fatal编程技术网

C# 无法将收集数据发布到控制器操作

C# 无法将收集数据发布到控制器操作,c#,asp.net-mvc,asp.net-mvc-4,asp.net-mvc-controller,C#,Asp.net Mvc,Asp.net Mvc 4,Asp.net Mvc Controller,我是MVC初学者,尝试将集合发布到控制器操作,但在控制器中,它显示集合的计数=0。我尝试过许多不同的方法,但没有成功 我有两个视图模型(PatientViewModel、PatientSetViewModel),在患者视图模型内部,我有一个名为PatientSetViewModel的PatientSetViewModel集合。下面是代码 public class PatientViewModel { private MHUContext ctx = new MHUContext();

我是MVC初学者,尝试将集合发布到控制器操作,但在控制器中,它显示集合的计数=0。我尝试过许多不同的方法,但没有成功

我有两个视图模型(PatientViewModel、PatientSetViewModel),在患者视图模型内部,我有一个名为PatientSetViewModel的PatientSetViewModel集合。下面是代码

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; }
}
postedPatientVM.PatientTSVM.Count=0


有任何关于此计数为零的帮助/建议吗?请注意,编辑记录时就是这种情况(我有收集中的数据,但回传时,收集中的数据变为空)

您不能使用局部视图(除非您向其传递
HtmlFieldPrex
)。将您的部分重命名为
/Views/Shared/EditorTemplates/PatientTestViewModel.cshtml
和t=在主视图中使用
@Html.EditorFor(m=>m._PatientTestVM)
(无循环),但您的部分甚至不包含任何表单控件,因此没有任何可发回的内容(因此不清楚您想要做什么)我有一个表单控件“复选框”在部分视图中,(我忘了提到它)让我编辑我的问题。根据您的编辑,即使您这样做正确(如我前面所述使用
EditorTemplate
),提交时您将获得的
patienttesviewmodel
的唯一值是
\u PatientTest.test\u status
(我假设是布尔属性)。我假设您还需要一个ID属性的隐藏输入作为well@stephenMuecke谢谢,通过使用editortemplate,它现在显示PatientTestViewModel的集合。但是里面没有数据。我试图检查复选框的值,但它显示0。有什么帮助吗?
@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 }))
{
<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>
public ActionResult CreatePatient(PatientViewModel PostedPatientVM)
{
    if (ModelState.IsValid)
    {