Here is my scenario:
public class ComplexObject
{
public int SomeProperty {get;set;}
public List<SimpleObject> Object {get;set;}
}
public class SimpleObject
{
public string FirstName {get;set;}
public string LastName {get;set;}
}
I created a strongly typed partial view for SimpleObject
@model SimpleObject
<div>
<input type="button" value="Button" name="btn" />
<div>
<div>
@Html.TextBoxFor(Model => Model.FirstName, new { @class = "", @maxlength = "50" })
</div>
<div>
@Html.TextBoxFor(Model => Model.LastName, new { @class = "", @maxlength = "50" })
</div>
Now I want to Render this partial view inside another view (MainView). The idea is that a user can click SimpleObject partial view button and generate the same partial view again on the MainView . SO here is how it looks :
MainView
SimpleView -> Add
SimpleView -> Add
I can create an ajax action and generate the simple view and append it to mainview but the problem is that simpleobject is NOT binding to the ComplexObject.
This is how I render partialview in MainView.
@Html.Partial("_PartialView", Model.SimpleObject, new ViewDataDictionary(ViewData)
{
TemplateInfo = new System.Web.Mvc.TemplateInfo
{
HtmlFieldPrefix = "Simple"
}
})
The MainView calls a controller action on submit click and the entire ComplexObject
is submitted. Here my List of SimpleObject
is always NULL.
public ActionResult CreateComplex(ComplexObject object)
{
// HERE LIST<SIMPLEOBJECT> is always NULL
}
Any ideas what am I doing wrong here ?