I have ViewModel for example
class CustomerViewModel {
// ...
public string Name {get; set;}
public CategoryViewModel CategoryVM {get; set;}
}
class CategoryViewModel {
// ...
public string Name {get;set;}
}
In View i can get Id of an html element with html helper
<!-- Customer Name -->
@Html.IdFor(m => m.Name)
<!-- Category Name -->
@Html.IdFor(m => m.CategoryVM.Name)
But what if CategoryVM
is inserted into PartialView
@{Html.RenderPartial("~/.../_Category.cshtml", Model.CategoryVM);}
How to get Id of the property ? Because now i have two id's with same name. What is best practice for properties naming and handling in nested ViewModels ?
Also i dont want to pass whole Model to the PartialView because there are Ajax calls, which re-renders the partial view, and i dont want to build whole Model from scratch even for simple operations.