Asp.net mvc 5 将部分视图DropdownList值传递给MVC 5中的父视图模型

Asp.net mvc 5 将部分视图DropdownList值传递给MVC 5中的父视图模型,asp.net-mvc-5,Asp.net Mvc 5,我有一个引用模型的局部视图,该模型是使用@Html.RenderAction(“PartialView”、“Controller”)从父视图调用的。部分视图是Html.BeginForm的一部分。当父窗体呈现时,将显示下拉列表。当我填写其余表单字段并单击“创建”时,下拉列表中的值不包括在表单中。集合返回给控制器。如何将PartialView选定值传递给父视图模型 以下是我的部分观点: @model IEnumerable<ArdentTestv6.Repositories.SelectPr

我有一个引用模型的局部视图,该模型是使用@Html.RenderAction(“PartialView”、“Controller”)从父视图调用的。部分视图是Html.BeginForm的一部分。当父窗体呈现时,将显示下拉列表。当我填写其余表单字段并单击“创建”时,下拉列表中的值不包括在表单中。集合返回给控制器。如何将PartialView选定值传递给父视图模型

以下是我的部分观点:

@model IEnumerable<ArdentTestv6.Repositories.SelectProjectTypes_Result>

<div>
<select id="SelectProjectType" class="alert-danger" title="Please Select">
    <option id="0"></option>
    @foreach(var item in Model)
    {
        <option id="@item.TypeID"> @item.TypeName </option>

    }

</select>
</div>
@model IEnumerable
@foreach(模型中的var项目)
{
@item.TypeName
}
以下是我的家长观点:

@model ArdentTestv6.Repositories.ProjectList

@{
ViewBag.Title = "Create";
}

<h2>Create</h2>

@using (Html.BeginForm())
{
@*Html.AntiForgeryToken()*@

<div class="form-horizontal">
    <h4>ProjectList</h4>
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })

    <div id="projType" class="form-group">
        @Html.Label("Project Type", htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @{Html.RenderAction("_ListProjectTypes", "ProjectTypes", new { htmlAttributes = new { @class = "form-control" } });}
        </div>
    </div>
    <div class="form-group">
        @Html.Label("Project Type ID", htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @{Html.Label("This will hold the ID of the above Project Type", new { htmlAttributes = new { @class = "form-control" } });}
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.ProjectReference, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.ProjectReference, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.ProjectReference, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.ProjectName, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.ProjectName, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.ProjectName, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.ProjectDescription, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.ProjectDescription, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.ProjectDescription, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.ProjectManager, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.ProjectManager, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.ProjectManager, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.DateStart, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.DateStart, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.DateStart, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.DateCompleted, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.DateCompleted, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.DateCompleted, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Create" class="btn btn-default" />
        </div>
    </div>

</div>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>
@model-ArdentTestv6.Repositories.ProjectList
@{
ViewBag.Title=“创建”;
}
创造
@使用(Html.BeginForm())
{
@*Html.AntiForgeryToken()*@
项目列表

@Html.ValidationSummary(true,“,new{@class=“text danger”}) @Label(“项目类型”,htmlAttributes:new{@class=“controllabel col-md-2”}) @{Html.RenderAction(“_ListProjectTypes”,“ProjectTypes”,new{htmlAttributes=new{@class=“form control”}});} @Label(“项目类型ID”,htmlAttributes:new{@class=“controllabel col-md-2”}) @{Html.Label(“这将保存上述项目类型的ID”,new{htmlAttributes=new{@class=“form control”}});} @LabelFor(model=>model.ProjectReference,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.ProjectReference,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.ProjectReference,“,new{@class=“text danger”}) @LabelFor(model=>model.ProjectName,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.ProjectName,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.ProjectName,“,new{@class=“text danger”}) @LabelFor(model=>model.ProjectDescription,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.ProjectDescription,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.ProjectDescription,“,new{@class=“text danger”}) @LabelFor(model=>model.ProjectManager,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.ProjectManager,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.ProjectManager,“,new{@class=“text danger”}) @LabelFor(model=>model.DateStart,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.DateStart,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.DateStart,“,new{@class=“text danger”}) @LabelFor(model=>model.DateCompleted,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.DateCompleted,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.DateCompleted,“,new{@class=“text danger”}) } @ActionLink(“返回列表”、“索引”)

感谢您的帮助。

您在哪里以及如何调用局部视图?您好,我正在使用渲染从父视图调用局部视图(“\u ListProjectTypes etcTry也为选项提供了唯一的名称。您可以尝试的另一件事是在控制器中的不同字段下接收下拉列表的值,并将其添加回模型。