+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / MVC Routing in SiteFinity for default action

MVC Routing in SiteFinity for default action

3 posts, 0 answered
  1. arobadol
    arobadol avatar
    3 posts
    Registered:
    26 Jun 2006
    05 Mar 2015
    Link to this post

    Hello, I'm having trouble with the routing on SiteFinity. It all started with the need to use built in modules such News and the serach result... You can find some context on this post:

    https://plus.google.com/111682507631241506866/posts/fgxJDacCiwD

     My issue is the following. By default when not specified the action which is called on your controller is "Index". Let's suppose we have:

    a page with the URL "pagename",

    a widget "Widget" with the controller "WidgetController"

    and couple of actions "Index" and "Details"

    Here is what I understand from the routing resolution (URL to actions):

    server\pagename  -> Index()

    server\pagename\2015 -> Index(int? year)

    server\details -> Details()

    server\details\2015 -> Details(int? year)

    server\details\2015\10 -> Details(int? year,int? month)

    Now my question: Why those URLs DO NOT resolve to the following?

    server\pagename\2015\10 -> Index(int? year,int? month) -> I'm getting a 404

    server\pagename\2015\10\10 -> Index(int? year,int? month,int? days) -> I'm getting a 404

    server\pagename\2015\10\10\url-name -> Index(int? year,int? month,int? days,string urlname="") -> I'm getting a 404

    I have the feeling this is a bug, but I would like confirmation :)

     

     

  2. Laurent Poulain
    Laurent Poulain avatar
    17 posts
    Registered:
    01 Dec 2016
    09 Mar 2015
    Link to this post
    Hello,

    Thank you for contacting us.

    It looks like the use of options (int?) is confusing the MVC framework. Optional values can indeed be tricky when it comes to map the right values with the right variables.

    I was however able to achieve what you want by using default values instead of options:

    public ActionResult Details(int year=-1, int month=-1, int day=-1, string urlname="")
    {
        var model = new HelloWorldModel();
        model.Message = string.Format("Year={0}, Month={1}, Day={2}, URL='{3}'", year, month, day, urlname);
        return View("Default", model);
    }


    URLs such as /Details/2015, /Details/2015/10, /Details/2015/10/03 and /Details/2015/10/03/name were properly mapped.

    Regards,
    Laurent Poulain
    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
     
  3. arobadol
    arobadol avatar
    3 posts
    Registered:
    26 Jun 2006
    10 Mar 2015 in reply to Laurent Poulain
    Link to this post

    Hello Laurent,

     thanks for taking the time to test the routing. The use of an explicit action route such as "Details" in the url <pageName>/Details/int/int/int works correctly :) this is what I meant by

    server\details -> Details()

    server\details\2015 -> Details(int? year)

    server\details\2015\10 -> Details(int? year,int? month)

    The urls maps to the operation Details as listed above.  

    My difficulties was coming from the default action route "Index". This route is used by default when you do not mention any action route in the URL. It will maps to the operation "Index".

    <pageName>/int maps correctly to Index(int?)

    My problem was coming from the fact that

    <pageName>/int/int does NOT map to Index(int?,int?) as oppose to Details to an explicit action route url like when using the route "Details" :)

    I had an answer from someone on the feather Github discussion. The answer is simply that the routes "Index" and "Details" are particular routes! They are used in the master details scenario.

    <pageName>/int will map to Index(int?) and the int is used for paging list and you should not use it with more parameters.

    <pageName>/urlname -> Details (ItemType?) is used to display a specific item coming from the list or from the search result.

    Again thanks a lot for your help and hope our thread here will help other developers who (like me) have not read this blog post https://github.com/Sitefinity/feather/wiki/How-to-implement-a-Master-Detail-content-controller

    Alex.

3 posts, 0 answered