Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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# 无法将ViewModel中的属性与表单元素绑定_C#_Asp.net Mvc_Binding_Viewmodel - Fatal编程技术网

C# 无法将ViewModel中的属性与表单元素绑定

C# 无法将ViewModel中的属性与表单元素绑定,c#,asp.net-mvc,binding,viewmodel,C#,Asp.net Mvc,Binding,Viewmodel,我有一份表格,如下: 根据用户在上一屏幕中选择的“胶囊大小”,您看到的填充列表可能会有所不同。换句话说,如果用户在上一屏幕中选择“胶囊0”并单击提交,则此屏幕将显示该胶囊的填充物列表。这一切都很完美。我需要能够做的是捕获此表单上选择的填充符。当用户单击此表单上的“创建”时,代码将调用“流程”控制器中的“GetResults”方法: public ActionResult GetResults(ProcessViewModel vm) { List<Results> resu

我有一份表格,如下:

根据用户在上一屏幕中选择的“胶囊大小”,您看到的填充列表可能会有所不同。换句话说,如果用户在上一屏幕中选择“胶囊0”并单击提交,则此屏幕将显示该胶囊的填充物列表。这一切都很完美。我需要能够做的是捕获此表单上选择的填充符。当用户单击此表单上的“创建”时,代码将调用“流程”控制器中的“GetResults”方法:

public ActionResult GetResults(ProcessViewModel vm)
{
    List<Results> results = context.GetResults();
    return View(results);
}
公共操作结果GetResults(ProcessViewModel虚拟机) { List results=context.GetResults(); 返回视图(结果); } 下面是我的ViewModel,这个特定的视图是在它上面运行的:

public class ProcessViewModel
{
    public audit_session AuditSession { get; set; }

    public int NumberOfCapsules { get; set; }

    public int CapsuleFK { get; set; }

    public audit_ingredient_active Active1 { get; set; }
    public audit_ingredient_active Active2 { get; set; }
    public audit_ingredient_active Active3 { get; set; }
    public audit_ingredient_active Active4 { get; set; }
    public audit_ingredient_active Active5 { get; set; }
    public audit_ingredient_active KeyActive { get; set; }

    public audit_ingredient_filler Filler { get; set; }

    public bool E4M { get; set; }
    public bool K100M { get; set; }

    public List<filler> Fillers { get; set; }
}
公共类ProcessViewModel
{
公共审核会话审核会话{get;set;}
公共整数{get;set;}
公共int-CapsuleFK{get;set;}
公共审计\u成分\u活动1{get;set;}
公共审计\u成分\u活动2{get;set;}
公共审计要素活动3{get;set;}
公共审计要素活动4{get;set;}
公共审计_成分_活动{get;set;}
公共审计_component _activekeyactive{get;set;}
公共审计_成分_填充{get;set;}
公共bool E4M{get;set;}
公共布尔K100M{get;set;}
公共列表填充符{get;set;}
}
我想能够做的是捕获所选的填充,并以某种方式将其绑定到ViewModel中的填充。我该怎么做?其他所有内容都正确绑定(E4M、K100M以及表单上您看不到的所有其他字段)

下面是我的填充列表的标记形式-我怀疑这里有问题,因为我对这个标记不是100%有信心

    <label>Choose Filler:</label><br />
    <fieldset data-role="controlgroup">
        @foreach (var i in Model.Fillers)
        {
            @Html.RadioButtonFor(x => x.Filler, "false", new { name = "radio-choice", id = i.pk });
            <label for="@i.pk">@i.name</label>
        }
    </fieldset>
选择填充:
@foreach(模型中的var i) { @RadioButton(x=>x.Filler,“false”,新的{name=“radio choice”,id=i.pk}); @i、 名字 }
因为您要覆盖单选按钮名称,所以您可以尝试手动绑定
Filler
属性,而不是依赖默认的模型绑定器


您可能需要在控制器签名中添加一个额外的
string radio\u choice
参数(或使用
Request.Form[“radio choice”]
直接捕获它),并将它们分配给
vm

Filler
属性。为什么要自定义单选按钮的id和名称?因为它的名称需要命名为“单选”,以便jQuery Mobile将其呈现为您在表单上看到的UI按钮……您使用的是什么版本的MVC?