MVC Routing in 5.1
I have a controller in 5.1 MVC with 2 ActionResults:
Index()
and
Details(string product)
Each of them gets hit when I would expect (eg /mypage/ and /mypage/details/product1), but the "product" parameter (in this case "product1") never gets assigned - it shows as null when debugging.
Do I have to do anything to set up routes? I downloaded the music store example and see that routing in that works as expected (eg Browse(string Genre)), and I don't see anything explicitly setting routes in there, so I'm not sure.
Thanks in advance
Jonathan
By default, ASP.NET MVC, has a numeric (int) parameter called 'id' that would typically be used in this instance. Your details method would look like this:
// the new object contains any needed named parameters for the url.
// the helper will automatically build a URL according to the best matching URL rules.
<a href="@Url.Action("Details", "ControllerName", new product = "product1")">Product 1</a>Yeah, ivan (in the videos) uses UrlName as the value...but that brings up a question I have going through that sample
I don't want my url to look like
/recipies/Details/cookie
(with Details being the view)
I want it just
/recipies/cookie
...and Details shouldn't be uppercase
(I'm clearly not an MVC expert :)
Hi Dan
public ActionResult Browse(string Genre)As I suspected, the view uses 'named parameters' in the URL which is constructed with a typical helper. (the named parameters are the items inside new ...parameters here... )
@model IEnumerable<SitefinityWebApp.Mvc.Models.Genre> @foreach (var genre in Model) <li>@Html.ActionLink(genre.Name, "Browse", new Genre = genre.Name)</li> public ActionResult Browse(string Genre) ...Oh my gosh I figured out my issue!
If you think it's a bug please please report it :) The powers that be might not be monitoring this thread and so we'd want this in on the next SP if possible!
yeah, I'm doing that right now ;)
Seriously?! Well I am glad you found it then. I will test that when I get my site updated from 5.0 to 5.1 as well.
Hello,
I am sorry that I have only now seen this thread and would like to apologize to all.
We have found this issue, and yes indeed, it is a bug. We already have a fix in place and we'll release it sometime next week - with few other things.
As, for how the routing works - here is a very brief explanation. Sitefinity uses routing engine since 4.0 (so, for quite a long). When you are working in pure or hybrid modes, the route is actually picked up by the page. The page then constructs dynamically new routes for the MVC based widgets - which may or may not respond to it. If at least one of the widgets can handle the route data, page will render - otherwise you'll get 404. In a word - you should use route registrations only for classic MVC (side by side apps) mode.
"with few other things"
<fingerscrossed>Widgets, Widgets, Widgets, Widgets</fingerscrossed>
@Ivan: In regard to Steve's query about changing the route from: