Asp.net mvc 将值从EditorFor传递到控制器

Asp.net mvc 将值从EditorFor传递到控制器,asp.net-mvc,asp.net-mvc-3,Asp.net Mvc,Asp.net Mvc 3,这是我的观点,教育是模型中的列表 @using chpayroll.Models.CustInformations @model CustInfoExtract @Html.HiddenFor(x => x.flag, new { @id = "flag" }) @Html.HiddenFor(x => x.StaffId) <table style=" width:730px"> <tr>

这是我的观点,教育是模型中的列表

 @using chpayroll.Models.CustInformations
 @model CustInfoExtract

 @Html.HiddenFor(x => x.flag, new { @id = "flag" })
      @Html.HiddenFor(x => x.StaffId)
        <table style=" width:730px">    
            <tr>
                <th>Country</th>
                <th>Board</th>
                <th>Level</th>
                <th>PassedYear</th>
                <th>Division</th>
            </tr>     
            <tr> 
               @Html.EditorFor(x => x.education)
            </tr>
            <tr>
               <td><input type="submit" value="Add Another" id="addedu"/> </td> 
            </tr>
        </table> 
@使用chpayroll.Models.CustInformations
@模型CustInfoExtract
@Html.HiddenFor(x=>x.flag,新的{@id=“flag”})
@Html.HiddenFor(x=>x.StaffId)
国家
董事会
水平仪
过去的一年
分部
@EditorFor(x=>x.education)
我有如下编辑器模板

@using staffInfoDetails.Models
@model staffInfo.education

@Html.HiddenFor(x=>x.staffId)

<tr>
    <td >@Html.DropDownListFor(x => x.country, Model.countryList, "--select--", new { @id="country"})</td>
    <td>@Html.TextBoxFor(x => x.board, new { @id="board"})</td>
    <td>@Html.TextBoxFor(x => x.level, new { @id="level"})</td>
    <td>@Html.TextBoxFor(x => x.passedYr, new { @id="passedYr"})</td>
    <td>@Html.DropDownListFor(x => x.passedDiv, Model.passedDivList, "--select--", new { @id="division"})</td>
</tr>
@使用StaffInfo.Models
@斯塔夫信息教育模型
@Html.HiddenFor(x=>x.staffId)
@DropDownListFor(x=>x.country,Model.countryList,“--select--”,new{@id=“country”})
@TextBoxFor(x=>x.board,新的{@id=“board”})
@TextBoxFor(x=>x.level,新的{@id=“level”})
@TextBoxFor(x=>x.passedYr,新的{@id=“passedYr”})
@DropDownListFor(x=>x.passedDiv,Model.passedDivList,“--select--”,new{@id=“division”})

我试图将模型从一个控制器传递到另一个视图,再从一个视图传递到另一个控制器。当我将模型传递到视图时,教育列表传递了,但是,当我尝试将模型从视图传递到控制器时,除了教育列表之外,其他所有内容都传递了。如何解决此问题?

只有从下拉列表中选择的值将被发回,因此如果验证失败(即,如果必须重新显示视图),您需要重新填充下拉列表

您的POST操作可能与以下内容类似:

[HttpPost]
public ActionResult Home(CustInformations viewModel)
{
    if (!ModelState.IsValid)
    {
        // Re-populate drop-down list and redisplay form
        viewModel.DropdownListOptions = _repository.getEductionList();
        return View(viewModel);
    }

    // Validation passed
    // Save, update, etc and redirect to new page
}