Detail action trouble with model
I am trying to implement a detail view following this documentation.
http://docs.sitefinity.com/feather-implement-master-detail-content-controllers
My controller has this:
public
ActionResult Details(DynamicContent physician)
return
View(physician);
My view has this:
@model Telerik.Sitefinity.Frontend.Mvc.Models.ContentDetailsViewModel
@Model.Item.Fields.LastName
and it fails with this error: The model item passed into the dictionary is of type 'Telerik.Sitefinity.DynamicTypes.Model.Physicians.Physician', but this dictionary requires a model item of type 'Telerik.Sitefinity.Frontend.Mvc.Models.ContentDetailsViewModel'.
Yet if I were to look at the auto-generated template for Physicians Sitefinity is using Telerik.Sitefinity.Frontend.Mvc.Models.ContentDetailsViewModel as the model type.
I looked around at samples and widgets for feather and can see where the News widget for feather initializes its own viewmodel first with CreateDetailsViewModel(newsItem), but that does not seem to be a method I can use. Do I need to roll my own method to cast a viewmodel I want to use when dealing with feather?
Edit: For now I went ahead and added a CreatePhysicianViewModel method to my service layer and am setting everything I need and it seems to be working, but still wouldn't mind an official answer of sorts on whether I should have been able to use it the other way.
Hi Stacey,
As far as I understand you have created a custom MVC widget to display the dynamic module items and their details. In this case you need to create also a custom view model and pass this view model in the MVC controller to the View.
In cases when you would like to create a new widget template for the build-in widget of your dynamic module type, you can use the below model in your View:
@model Telerik.Sitefinity.Frontend.Mvc.Models.ContentDetailsViewModel