MVC Routing in SiteFinity for default action
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:
plus.google.com/.../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 :)
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);
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 github.com/.../How-to-implement-a-Master-Detail-content-controller
Alex.