November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Are you sure you are registering view template on the right type (e.g. typeof(MyPageViewModel)
)?
Hi Nat,
You can simply use ASP.NET MVC conventions to render that view model list (as it is of type List<MyPageViewModel> or IList<MyPageViewModel> in your view model of type ListingPageViewModel).
So to have only a custom display template for the type MyPageViewModel, create a new view file under '~/Views/Shared/DisplayTemplates/MyPageViewModel.cshtml' and use the type MyPageViewModel as that views model, so something like this:
@model Your.Namespace.ToThe.MyPageViewModel
@* print out the models properties the way you need *@
<h3>@Model.Page.Name</h3>
<img src="@Model.TeaserImagePath" alt="Page teaser image" />
Then in your "calling" view you would simply write:
@Html.DisplayFor(m => m.List)
And framework will automatically then call for each item in the list that display template just created for the "MyPageViewModel".
If for example you want to create a HTML list of the objects (MyPageViewModel) you could create a display template for the list. Create a new view '~/Vies/Shared/DisplayTempates/ListOfMyPageViewModel.cshtml' (the part in the view file name is your template name => ListOfMyPageViewModel is the template name in this case, you can name it in anyway you like as you will be passing the template name in the code so there is no automagic convention based template name resolving in this case)
The view file content for ListOfMyPageViewModel.cshtml:
@model IList<Namespace.ToYOur.Type.Here.MyPageViewModel>
@if (Model != null && Model.Count > 0)
{
<ul>
@foreach (var pageItem in Model)
{
@* naturally you have your own stuff here ;-) *@
<li><img src="@pageItem.TeaserImagePath" alt="@pageItem.Page.Name" /></li>
}
</ul>
}
And then you would call it like this from your page cshtml:
@Html.DisplayFor(m => m.List, "ListOfMyPageViewModel")
Hope this helps.
I am trying to implement some extra templates for some pages/blocks using the IViewTemplateModelRegistrator.
This works fine when I am dealing with the Page or Block type itself, but if i use a ViewModel it does not pick the view.
does this only work when the type used is a Block or Page?
nothing gets rendered for the above PropertyFor, do I need to Create a (2nd) controller for the MyPage type and load the image in that instead?