Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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
Loops dropdownlistfor未设置值,而循环模型甚至在SelectList构造函数中传递值_Loops_Model_Dropdownlistfor - Fatal编程技术网

Loops dropdownlistfor未设置值,而循环模型甚至在SelectList构造函数中传递值

Loops dropdownlistfor未设置值,而循环模型甚至在SelectList构造函数中传递值,loops,model,dropdownlistfor,Loops,Model,Dropdownlistfor,我的模型 public class ExpenseEntryItems { public List<ExpenseEntryModel> NewItemList { get; set; } public List<SelectListItem> PaymentMethodList { get; set; } public List<SelectListItem> ActionList { get; set; } } public class E

我的模型

public class ExpenseEntryItems 
{
  public List<ExpenseEntryModel> NewItemList { get; set; }
  public List<SelectListItem> PaymentMethodList { get; set; }
  public List<SelectListItem> ActionList { get; set; }
}

public class ExpenseEntryModel
{
    [Display(Name = "Payment Method")]
    public string PaymentMethod { get; set; }

    [Display(Name = "Action")]
    public string Action { get; set; }
}
公共类费用项目
{
公共列表NewItemList{get;set;}
公共列表PaymentMethodList{get;set;}
公共列表操作列表{get;set;}
}
公共类支出项目模型
{
[显示(Name=“付款方式”)]
公共字符串PaymentMethod{get;set;}
[显示(Name=“操作”)]
公共字符串操作{get;set;}
}
MyView

@model REMClient.Models.ExpenseEntryItems
@using (Html.BeginForm("SubmitForm", "Expenses", FormMethod.Post, new { enctype = "multipart/form-data", id = "frmFileUpload" }))
{
  @foreach (var i=0; i<Model.NewItemList.Count; i++)
  {
     @Html.DropDownListFor(modelItem => modelItem.NewItemList[i].PaymentMethod, new SelectList(Model.PaymentMethodList, "Value", "Text", Model.NewItemList[i].PaymentMethod), new { @class = "obj grid", id = "ddlPayMethod_" + Model.NewItemList[i].ExpDetailId })

     @Html.DropDownListFor(modelItem => modelItem.NewItemList[i].Action, new SelectList(Model.ActionList, "Value", "Text", Model.NewItemList[i].Action), new { @class = "obj grid", id = "ddlAction_" + Model.NewItemList[i].ExpDetailId })
  }
}
@model REMClient.Models.ExpenseEntryItems
@使用(Html.BeginForm(“SubmitForm”,“Expenses”,FormMethod.Post,new{enctype=“multipart/formdata”,id=“frmFileUpload”}))
{
@foreach(var i=0;i modelItem.NewItemList[i].PaymentMethod,new SelectList(Model.PaymentMethodList,“Value”,“Text”,Model.NewItemList[i].PaymentMethod),new{@class=“obj grid”,id=“ddlPayMethod”+Model.NewItemList[i].ExpDetailId})
@Html.DropDownListFor(modeleItem=>modeleItem.NewItemList[i]。操作,新选择列表(Model.ActionList,“Value”,“Text”,Model.NewItemList[i]。操作),新{@class=“obj grid”,id=“ddlAction”+Model.NewItemList[i].ExpDetailId})
}
}
在控制器中,我用值填充内部模型列表。 在视图中,它加载列表的第一个值,并设置为剩余值的选定值 网格中的dropdownlistfor

但是,如果我按照如下方式实现dropdownlistfor,它将在视图中显示值,但在发布后不会在控制器中获取列表值

@using (Html.BeginForm("SubmitForm", "Expenses", FormMethod.Post, new { enctype = "multipart/form-data", id = "frmFileUpload" }))
{
   @foreach (var i=0; i<Model.NewItemList.Count; i++)
   {
      string payment = Model.NewItemList[i].PaymentMethod;
      string action = Model.NewItemList[i].Action;
      @Html.DropDownListFor(modelItem => payment , new SelectList(Model.PaymentMethodList, "Value", "Text", payment ), new { @class = "obj grid", id = "ddlPayMethod_" + Model.NewItemList[i].ExpDetailId })

      @Html.DropDownListFor(modelItem => action , new SelectList(Model.ActionList, "Value", "Text", action ), new { @class = "obj grid", id = "ddlAction_" + Model.NewItemList[i].ExpDetailId })
  }
}
@使用(Html.BeginForm(“SubmitForm”,“Expenses”,FormMethod.Post,new{enctype=“multipart/formdata”,id=“frmFileUpload”}))
{
@foreach(var i=0;i付款,新选择列表(Model.PaymentMethodList,“Value”,“Text”,付款),新{@class=“obj grid”,id=“ddlPayMethod”\+Model.NewItemList[i].ExpDetailId})
@Html.DropDownListFor(modeleItem=>action,new-SelectList(Model.ActionList,“Value”,“Text”,action),new{@class=“obj-grid”,id=“ddlAction”\+Model.NewItemList[i].ExpDetailId})
}
}
请给我一个正确的实施方法