sitefinitysitefinity-10

How to create controller action for details view


Inherited a Sitefinity site. Need to add a MVC widget for the details view on the news pages.

I found this documentation but I can't make heads or tails of it - maybe it was for a different version. I finally found the UrlkeyPrefix buried deep in the news widget options, but following the instructions of the documentation added "!content" in the middle of my details page URL (which I can't have happening) and still did not display my custom widget.

Does anyone know how to correctly configure the controller to get the widget to show up for the details pages?


I sort of got the example in the documentation to work, except that there's this very annoying "!content" in my URL still

https://mysite/news/!content/2017/08/24/my-article-title

 [ActionName("!content")]
 public ActionResult Filter()
 {
     return View("index", InitializeModel());
 }

Navigating to the URL sans "!content" just shows the list page.


Solution

  • The nature of MVC is such that you're only able to invoke one action at a time.

    Assuming that you're invoking the Details action on the NewsController, the other widget you've placed on the page won't understand how to respond to a Details action unless you do one of two things:

    1. Create a corresponding Details action in your own controller OR
    2. Override HandleUnknownAction to handle what you want to happen when another widget's method is invoked. (better, as it reduces ambiguity)

    If you want to invoke your Index action on your custom widget when the Details action is invoked on News:

        protected override void HandleUnknownAction(string actionName)
        {
            this.ActionInvoker.InvokeAction(this.ControllerContext, "Index");
        }