我有4个动作结果
public ActionResult Parent1 ()
{
ViewModel VM = new ViewModel ();
return View(VM);
}
[HttpPost]
public ActionResult Parent1(ViewModel VM)
{
return View(VM);
}
[ChildActionOnly]
public ActionResult PortfolioComposition(ViewModel VM)
{
string UserId = "UserId1";
VM.PortfolioUserName = "ac";
VM.PList = new List<PortfolioBar>();
PortfolioBar bar = new PortfolioBar();
bar.Category = "a";
bar.InstrumentName = "a";
bar.Weight = "c";
bar.XyzStats = "d";
vm.PortBarList.Add(bar);
return View(vm);
}
[ChildActionOnly]
public ActionResult Partial2(ViewModel VM)
{
return View(VM);
}
在视图模型中
public class ViewModel
{
public String PortfolioUserName { get; set; }
public List<PortfolioBar> PortBarList = new List<PortfolioBar>();
}
public class PortfolioBar
{
public string InstrumentName { get; set; }
public string Category { get; set; }
public string Weight { get; set; }
public string XyzStats { get; set; }
}
父视图
@using (Html.BeginForm())
{
@{ Html.RenderAction("Partial1", "Home", new { vm = Model }); }
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Search" class="btn btn-default" />
</div>
}
Partial1查看
@foreach (var item in Model.listvm)
{
@{ Html.RenderAction("Partial2", "Home", new { vm = Model }); }
}
partial2查看
@TextBoxFor(m => m.weight)
以上代码中的所有内容都是公开的。 我希望在回发到父控制器时获得重量值。我不知道该怎么做。可能是我做错了什么。 我用相同的物体做它是不是很好?还是我需要使用另一个物体?但是,我将如何在帖子上合并这两个对象?