How to display MVC widget in detail views of content items

by
User Not Found
Dec 15, 2012

When placing MVC widgets on pages that also display blog posts, news items or dynamic content created with the module builder you may have noticed when blog post or any other content on a page when displayed in its details view doesn`t show the MVC widgets.

This is happening because when content is displayed in details view the url of the page appends the url for details view.

For example if you open a page with this url http://mysite.com/page the MVC widget will render as the route where the MVC controller will be searching for action result will be the page route ( /page ).

When a news item among a list of news items is selected on this page and the whole news item appear the url becomes http://mysite.com/page/2012/12/15/latest-headlines.
On this url the MVC widget is gone as its controller can`t find the correct route to render MVC view.

To address this in the most appropriate way is to add UrlkeyPrefix for all content widgets on a page. Add the same prefix for blogs, news module builder widgets and other.

Add the same UrlkeyPrefix to each content widget on this page that will render details view. To render In the controller create a new action and put ActionName attribute to this method specifying the action name to the following : !{UrlKeyPrefix} (ex. [ActionName("!content")]). Note:remember to put the exclamation mark before the key prefix ( ! )

In the controller class of the MVC widget add new action to render the controller view when the page currently displays details view of content item and the URL of the details view is http://mysite.com/page/content/2012/12/15/latest-headlines .

8 comments

We are using this approach but are now finding that our search results and RSS feeds no longer work when linking in to the module detail pages because the URLs do not include the UrlKeyPrefix. Is there any way to globally specify that links to a page should include the UrlKeyPrefix, or otherwise can we set it somehow for the Search and RSS widgets?

Jeff Jul 08, 2014

@Scott, the following code allows you to use the same handler for any actions:

Thanks @Jeff, that seems like a much better solution than the solution provided in the blog post.

Joe C Jun 03, 2015

Thank you Jeff. I am confirming that the solution Jeff provided worked for me as well.

Saurav May 04, 2016

@Jeff I used the solution provided by you but all the widgets (NewsList and slider) other than navigations and footer disappear on calling the detailsview action method shown below. I applied breakpoint on handleunknownaction method and found out that it is not getting hit. Kindly, help.

@stanislav I have created a custom feather MVC widget without a designer. In order to use your solution, I need to access the advanced properties of the custom widget. The problem is that I cannot find the advance button on the designer. A blank designer pops up with a save button. Please help.

David Chelliah May 28, 2016

Hey Saurav,

If you would have designed the control using SimpleViewWidget Class, the mentioned property will be available. Since you have created a custom MVC widget, you need to use the method noted by Jeff.

Writing a UnknowAction Handle - where you can select the Action to execute based on some value set in the HttpContext property or may be URL name

You can see the related explanation about the MVC behaviour in the following link.

Tools

Sitefinity Professional Services

Progress, Telerik, Sitefinity and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries.