Note that there are some explanatory texts on larger screens.

plurals
  1. POURL building in ASP.NET MVC
    primarykey
    data
    text
    <p>I have got four routes defined like this:</p> <pre><code>//Project list with page number routes.MapRoute( "Filtered projects 1", "Projects/All/{page}", new { controller = "Projects", action = "All", page = UrlParameter.Optional } ); //Project list with page number and filtering by region routes.MapRoute( "Filtered projects 2", "Projects/All/Regions/{regions}/{page}", new { controller = "Projects", action = "All", regions = UrlParameter.Optional, page = UrlParameter.Optional} ); //Project list with page number and filtering by subject routes.MapRoute( "Filtered projects 3", "Projects/All/Subjects/{subjects}/{page}", new { controller = "Projects", action = "All", subjects = UrlParameter.Optional, page = UrlParameter.Optional } ); //Project list with page number and filtering by region and subject routes.MapRoute( "Filtered projects 4", "Projects/All/Regions/{regions}/Subjects/{subjects}/{page}", new { controller = "Projects", action = "All", regions = UrlParameter.Optional, subjects = UrlParameter.Optional, page = UrlParameter.Optional } ); </code></pre> <p>This allows me to have a paged list which can also be filtered by Regions or Subjects.</p> <p>I want to make a series of links with the subjects, such that I can click on a subject and it will return the one of the urls above as required, with the /Subjects/<em>SubjectName</em> bit appended as required. I also want to allow the user to click on several links, which should give urls like above with /Subjects/<em>subject1</em>_*subject2*_<em>subject3</em>.</p> <p>I just can't figure out how to do this. I've got the list of subjects showing in a partial view. When I generate the hyperlinks, how can I get to the url and modify (or add or removed as required) the /Subjects/<strong>*</strong> part?</p> <p>It was easy with querystrings, because they could easily be broken into value paris, but with these beautiful urls it seems quite difficult... Any tips?</p> <p>UPDATE: I forgot to add that I would like to use this filtering method with different actions on the same controller. Not sure if that matters, but I thought I'd be precise.</p> <p>UPDATE 2: I think my question isn't quite clear enough...</p> <p>What I am trying to do is generate a link for each subject in my partial view with respect to the link from the main view. The catch is that the link needs to conform to one of the routes above.</p> <p>Say, I call this from /localhost/Projects/All and want to sort by subject1, I would want to get urls saying /localhost/Projects/All/Subjects/subject1. If I called this from /localhost/Projects/Search/Something/10 (i.e. page 10 of the results for search "Something", I haven't got this route in the list, but it is in the works), I would want urls like localhost/Projects/Search/Something/Subjects/Subject1/10. Or for that matter going from /localhost/Projects/All/4 to localhost/Projects/All/Subjects/subject1/4.</p> <p>I can easily append the /Subjects/Subject1 bit to the URL, but then doesn't conform to my routes anymore... In other words, how can I extract the various bits from my url, modify them and then stitch them back together?</p> <p>Is this possible? Or should I just forget prettyness and use querystrings?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload