2017-12-23 20 views
0

パーシャルビューフォームの値だけがコントローラに渡されません:FounderInvestmentVMはパーシャルビューを作成したVMです。他の値はパーシャルビューのものではなくコントローラに渡されます。私は、デバッガを入れて、それを見るとき、それは常にFounderInvestments Count=0を与える:/パーシャルビュー数= 0、コントローラに値が送信されていません

これはFounderInvestorVMを含むVM私の財産である: - これはFounderInvestorVMある

namespace propertyMgmt.ViewModel.PropertyViewModel 
{ 
    public class PropertyViewModel 
    {  
     public int? Id { get; set; } 
     [Required] 
     [DisplayName("Property Title")] 
     public string PropertyTitle { get; set; } 
     ...... 
     public List<FounderInvestmentViewModel> FounderInvestments { get; set; }=new List<>(FounderInvestmentViewModel); 
    } 
} 

: -

public class FounderInvestmentViewModel 
    { 
     public int? Id { get; set; } 
     public int PropertyId { get; set; } 
     public int InvestorId { get; set; } 
     public double Investment { get; set; } 
     public int InstallmentPeriod { get; set; } 
     public IEnumerable<SelectListItem> FounderInvestorList { get; set; } 
    } 

これは私のコントローラであり、 -

public ActionResult Create(PropertyViewModel _propertyViewModel) 
    { 
    if (ModelState.IsValid) 
     { 
     Property property = new Property(); 
     property.Id = _propertyViewModel.Id ?? 0; 
     property.PropertyTitle = _propertyViewModel.PropertyTitle; 
     ........other properties......   
     } 
     _propertyQueryProcessor.Create(property); 
     foreach(var investment in _propertyViewModel.FounderInvestments) 
      { 
       FounderInvestment _founderInvestment = new FounderInvestment 
       { 
        Id = investment.Id??0, 
        InstallmentPeriod = investment.InstallmentPeriod, 
        InvestorId = investment.InvestorId, 
        PropertyId = investment.PropertyId, 
        Investment = investment.Investment 
       }; 
       _founderInvestmentQueryProcessor.Create(_founderInvestment);  
    } 

これは一部です。 -

@model propertyMgmt.ViewModel.FounderInvestmentViewModel 
@{ 
    ViewData.TemplateInfo.HtmlFieldPrefix = "PropertyViewModel"; //bind to main model 
} 

<div class="founderInvestmentDetails"> 
    @using (Html.BeginCollectionItem("founderInvestmentDetails")) 
    { 
     @Html.HiddenFor(m => m.Id, new { @class = "id" }) 

     @Html.HiddenFor(m=>m.PropertyId, new { @name = "PropertyId" }) 

     <div class="form-group"> 
      @Html.LabelFor(m => m.FounderInvestorList, htmlAttributes: new { @class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.DropDownListFor(m=>m.FounderInvestorList,Model.FounderInvestorList , "Select Investor", htmlAttributes: new {@class = "form-control"}) 
       @Html.ValidationMessageFor(m => m.FounderInvestorList, "", new { @class = "text-danger" }) 
       @Html.HiddenFor(m => m.InvestorId, new { @name = "InvestorId" }) 
      </div> 
     </div> 

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

そして最後に、このメインビューである: - 申し訳ありませんが、愚かな間違いがあったhere.As @Stephen Mueckeは

@using (Html.BeginCollectionItem("founderInvestmentDetails")) 

を指摘

@model propertyMgmt.ViewModel.PropertyViewModel.PropertyViewModel 
    @using (Html.BeginForm("Create", "Property", FormMethod.Post, new { enctype = "multipart/form-data" })) 
    { 
    <div class="form-group"> 
     @Html.LabelFor(model => model.PropertyTitle, htmlAttributes: new { @class = "control-label col-md-2" }) 
     <div class="col-md-10"> 
      @Html.EditorFor(model => model.PropertyTitle, new { htmlAttributes = new { @class = "form-control" } }) 
      @Html.ValidationMessageFor(model => model.PropertyTitle, "", new { @class = "text-danger" }) 
     </div> 
    </div> 
    .....(other form groups) 
    <div id="founderInvestmentDetails" class="form-group"> 
     @foreach(var founderInvestmentDetails in Model.FounderInvestments) 
     { 
     @Html.Partial("_FounderInvestmentDetails", founderInvestmentDetails) 
     } 
    </div> 
+0

1. 'ViewData.TemplateInfo ...'コード行を削除します。 2.その 'BeginCollectionItem(" FounderIvestments ") - プロパティ名と一致します。 –

+0

@StephenMueckeあなたが無料ならばチャットを見てください:) – SudeepS

答えて

1

であるべき
@using (Html.BeginCollectionItem("FounderInvestments")) 

BeginCollectionItemはの名前を使用するためが作業中です。

関連する問題