Detail action trouble with model

Posted by Community Admin on 05-Aug-2018 19:12

Detail action trouble with model

All Replies

Posted by Community Admin on 30-Nov-2015 00:00

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.

 

 

 

 

Posted by Community Admin on 25-Dec-2015 00:00

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

Please refer to the below article for more details about creating widget templates and the convention that needs to be followed: http://docs.sitefinity.com/feather-work-with-widget-templates. If you create the your custom view for the built-in dynamic module widget following the conventions as described in the above article, when you open the built-in MVC module widget you will be able to select your custom template from the dropdown of widget templates.

In your case you are developing a brand new MVC widget with its own Views, Controllers and Models.

Regards,
Sabrie Nedzhip
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed