Asp.net core mvc DropdownlistFor在循环中,提交时为空模型

Asp.net core mvc DropdownlistFor在循环中,提交时为空模型,asp.net-core-mvc,Asp.net Core Mvc,提交表单时,控制器中的多个dropdownlistfor中选择的值可用,我遇到了一个问题。模型始终为空。我知道mvc在循环中有下拉菜单的问题,但我想我已经解决了这个问题。让我知道你的想法 查看 @model DataDictionaryConversion.Models.FinalResults @{ using (Html.BeginForm("SaveMapping", "Home", FormMethod.Post, null)) {

提交表单时,控制器中的多个dropdownlistfor中选择的值可用,我遇到了一个问题。模型始终为空。我知道mvc在循环中有下拉菜单的问题,但我想我已经解决了这个问题。让我知道你的想法

查看

@model DataDictionaryConversion.Models.FinalResults

@{ using (Html.BeginForm("SaveMapping", "Home", FormMethod.Post, null))
            {
                @Html.AntiForgeryToken()
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>Converted to Name</th>
                            <th>Your Project Name</th>
                            <th><input type="button" 
onclick="checkAll()"/></th>
                        </tr>
                    </thead>
                    <tbody>

                    @{for (int x = 0; x < Model.DDObjects.Count(); x++)
                        {
                            var isSelection = false;
                            <tr>
                                <td class="filterable-cell">@Model.DDObjects[x].ObjectName</td>
                                <td class="filterable-cell">

@Html.DropDownList(Model.DDObjects[x].ObjectName, new 
SelectList(Model.ProjectObjects, "ObjectName", "ObjectName"), 
htmlAttributes: new { @id = "ddlObject", @class = "js-example-basic-single" })</td>
                                </td>
                                <td>
                                    <input type="checkbox" id="NoValue- 
   @Model.DDObjects[x].ObjectName" name="NoValue- 
   @Model.DDObjects[x].ObjectName" onclick="byPassObject(this)" /> Object 
Not 
Used
                                </td>
                            </tr>
                        }
                    }
                </tbody>
                <tfoot>
                    <tr>
                        <td style="text-align:right; height:20px"><input 
type="submit" class="btn btn-warning" value="Generate Conversion Mapping" 
/></td>
                    </tr>
                </tfoot>
            </table>
        }
    }
型号

public class FinalResults
{
public IList<FinalObjectModel> ProjectObjects { get; set; }
public IList<Conversion_CSD_ObjectNameLearningModel> DDObjects { 
get; set; }
公共类最终结果
{
公共IList项目对象{get;set;}
公共IList DDObject{
get;set;}

FinalResults模型为空

您使用的是
Html.DropDownList
。第一个参数是一个字符串,它应该与您绑定到的名称相对应。但是,您传递的是
model.DDObjects[x].ObjectName的值
,而不是类似于
“DDOjbects[0].ObjectName”

相反,您应该使用
Html.DropDownListFor
如下所示:

@Html.DropDownListFor(m => m.DDObjects[x].ObjectName, ...)

然后,选择列表将被正确绑定。

哇,我甚至在描述中写下了它,但没有注意到我没有正确地键入。我猜这只是用了另一双眼睛。谢谢。
@Html.DropDownListFor(m => m.DDObjects[x].ObjectName, ...)