C# 在ActionResult创建中将多个模型传递给控制器

C# 在ActionResult创建中将多个模型传递给控制器,c#,model-view-controller,actionresult,C#,Model View Controller,Actionresult,我创建了四个模型,然后我创建了一个包含前四个模型的viewmodel,我创建了一个带有控制器的视图,显示了这个viewmodel 当我创建actioresultcreate(httppost)时,我不知道如何传递整个模型 视图模型: using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Avvisi.Models { public class PianoComp

我创建了四个模型,然后我创建了一个包含前四个模型的viewmodel,我创建了一个带有控制器的视图,显示了这个viewmodel

当我创建actioresultcreate(httppost)时,我不知道如何传递整个模型

视图模型:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Avvisi.Models
{
public class PianoCompletoViewModels
{
public Guid Id { get; set; }
public DatiPiano DatiPiano { get; set; }
public DescrizionePiano descrizionePiano { get; set; }
public ImpresaBeneficiaria impresaBeneficiaria { get; set; }
public ResponsabilePiano responsabilePiano { get; set; }
public ProspettoFinanziario prospettoFinanziario { get;set; }
}
}
控制器:

public ActionResult Create()
   {
string UserID = Convert.ToString(User.Identity.GetUserId());
int AvvisoID = Convert.ToInt32(Session["AvvisoID"]);
ViewBag.FKCompartoID = new SelectList(db.Comparto, "CompartoID", 
"Nome");
 ViewBag.PianoID = new SelectList(db.DescrizionePiano, 
"DescrizioneID", "PresentImpBenef_RelContAziend");
 return View();
 }
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(PianoCompletoViewController PianoView)
{
if (ModelState.IsValid)
{
return View();
}
return View();
}
我希望当我单击submit时,会有一个模型填充的wiht属性(其他MModel),例如:

PianoView.model1.xxx
PianoView.model2.xxx
PianoView.model3.xxx
PianoView.model4.xxx
cshtml视图:

@model Avvisi.Models.PianoCompletoViewModels

@{
    ViewBag.Title = "Create";
}

<h2>Dati Piano</h2>

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

<div class="form-horizontal">
    <h4>Dati Piano</h4>

    @Html.ValidationSummary(true, "", new { @class = "text-danger" })

<div class="row" style="margin-left:0px;margin-right:0px">
        <div class="form-group">
            @Html.LabelFor(model => model.DatiPiano.NomePiano, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.DatiPiano.NomePiano, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.DatiPiano.NomePiano, "", new { @class = "text-danger" })
            </div>
        </div>
    </div>

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

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

  <div class="form-group">
            @Html.LabelFor(model => model.responsabilePiano.Nome, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.responsabilePiano.Nome, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.responsabilePiano.Nome, "", 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" style="width:95%;background: #dedede;" />
        </div>
    </div>
</div>
}
@model Avvisi.Models.PianoCompletoViewModels
@{
ViewBag.Title=“创建”;
}
达蒂钢琴
@使用(Html.BeginForm())
{
@Html.AntiForgeryToken()
达蒂钢琴
@Html.ValidationSummary(true,“,new{@class=“text danger”})
@LabelFor(model=>model.DatiPiano.NomePiano,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.datipano.NomePiano,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.DatiPiano.NomePiano,“,new{@class=“text danger”})
@Html.LabelFor(model=>model.descripionePiano.PresentImpBenef_RelContAziend,htmlAttributes:new{@class=“control label col-md-2”})
@EditorFor(model=>model.descripionePiano.PresentImpBenef_RelContAziend,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.descripionePiano.PresentImpBenef_RelContAziend,“,new{@class=“text danger”})
@LabelFor(model=>model.impresaBeneficiaria.CompanyName,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.impresaBeneficiaria.CompanyName,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.impresaBeneficiaria.CompanyName,“,新{@class=“text danger”})
@LabelFor(model=>model.responsabilePiano.Nome,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.responsabilePiano.Nome,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.responsabilePiano.Nome,“,new{@class=“text danger”})
}
我不明白为什么不允许我选择正确的属性(模型)


您能帮助我吗???

您必须使用如下html控件名称:

<input name="descrizionePiano.someProperty">


那么,你肯定是物有所值了

在html中没有问题,我已经更新了我的主要帖子;问题是在提交“事件”中,当为create视图触发httpost时,我希望传递我的视图模型,但我无法访问它的属性。如果我编写公共操作结果创建(PianoCompletoViewController pianoView),我希望pianoView包含模型的属性,在这种情况下,我希望pianoView.datipiano、pianoView.DescriptionePiano等。。。但当我在点符号后写pianoview时,并没有属性。