I have a complex type License as a view model.
public class License
{
public string Name { get; set; }
// Other Properties
public List<Function> Functions { get; set; }
}
public class Function
{
public string Name { get; set; }
// Other Properties
public List<Unit> Units { get; set; }
}
public class Unit
{
public string Name { get; set; }
// Other Properties
}
Both the Function’s view template and Unit’s view template are dynamiclly rendered. So the html looks like this:
<!-- LicenseView -->
@model License
@Html.TextBoxFor(m => m.Name) // this is OK
@for(int i=0; i<Model.Functions.Count; i++)
{
@Html.Partial(Model.Functions[i].Name, Model.Functions[i])
}
and the FunctionView may look like this
@model Function
@Html.TextBoxFor(m => m.Name) // the generated html element's name is just 'Name'
@for(int i=0; i < Model.Units.Count; i++)
{
@Html.Partial(Model.Units[i].Name, Model.Units[i])
}
and this is UnitView
@model Unit
@Html.TextBoxFor(m => m.Name) // the generated html element's name is just 'Name'
So my question is, what should I do the make the Name attribute correct?
Thanks a lot
As @Jack said… you can do this using Editors instead of PartialViews.
BUT… if you really want to use PartialViews, you can do it, but the model to pass should be the top one (License). This way is similar of what David Jessee proposed, but splitting the one view in several.