0
부분 뷰 형식의 값만 컨트롤러로 전달되지 않습니다./FounderInvestmentVM은 부분 뷰를 생성 한 것이며이 VM은 다른 값은 컨트롤러로 전달되지만 부분 뷰의 값은 전달되지 않습니다. 이 FounderInvestorVM을 포함하는 내 재산 VM이/부분 뷰 수 = 0, 컨트롤러에 값이 전송되지 않음
이다 : 그것은 항상 내가 디버거를 넣어 볼 FounderInvestments Count=0
제공 -
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);
}
}
이것은 FounderInvestorVM입니다 : -
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>
그리고 마지막으로이 주요 VIEW는 다음과 같습니다 -
은@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>
1.'ViewData.TemplateInfo ...'코드 줄을 제거하십시오. 2. 그것의'BeginCollectionItem ("FounderIvestments")는 속성 이름과 일치합니다. –
@StephenMuecke 당신이 무료면 채팅을 참조하십시오 :) – SudeepS