I think this is what you are trying to achieve:
Say that in your model you have an Employee (or a list, either):
Employee Employee { get; set; }
So, your main view should have the following:
@Html.DisplayFor(Model => Model.Employee);
But how can I create a template, you ask?
You should take a step back at this point and consider creating a new ViewModel, EmployeeViewModel (this, in your opinion, should be your "partial view").
So now you will have:
EmployeeViewModel Employee { get; set; }
Now create a folder in your views / general calls to DisplayTemplates and create EmployeeViewModel.cshtml. To be clear, you now have / Views/Shared/DisplayTemplates/EmployeeViewModel.cshtml .
The top line of this should be read:
@model YourNamespace.EmployeeViewModel
And now you can just use in this view:
@Html.LabelFor(model => model.EmployeeName)
That should be enough to get you started.
source share