I have 4 Action results
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);
}
In view Model
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; }
}
Parent View
@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 View
@foreach (var item in Model.listvm)
{
@{ Html.RenderAction("Partial2", "Home", new { vm = Model }); }
}
partial2 View
@TextBoxFor(m => m.weight)
Everything is public in above code. I want to get value of weight on postback to parent controller. I don't know how to do it. May be I am doing something wrong. Is it fine that I am doing it with same object? or do I need to use another object ? But then how will I merge those two objects on post back?