Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC 3 - Slashes and spaces in route
    primarykey
    data
    text
    <p>I have the following route defined in my Global.asax (MVC 3 web project):</p> <pre><code>routes.MapRoute( "BlogCategory", // Route name "Blog/Category/{*category}", // URL with parameters new { controller = "Blog", action = "Index", category = "" } // Parameter defaults ); </code></pre> <p>And my action accepts a category parameter, looking like this:</p> <pre><code> public ViewResult Index(string category, int page = 1) { PostListViewModel viewModel; if (string.IsNullOrEmpty(category)) { ....show all cats else show only the one passed in </code></pre> <p>This works fine and will pass the category through to the controller, filtering my results appropriately.</p> <p>My problem is when one of the categories I created looks like this for it's category name:</p> <blockquote> <p>Projects / Lab</p> </blockquote> <p>(note the spaces and slash)</p> <p>This creates a URL similar like this:</p> <blockquote> <p>/Blog/Category/Projects%20/%20Lab</p> </blockquote> <p>And when I follow the link, I get this error:</p> <blockquote> <p>Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. </p> <p>Requested URL: /Blog/Category/Projects / Lab</p> </blockquote> <p>It never reaches the index action when debugging.</p> <p>My question is, how can I make this work, or must I do some input validation when creating category names to prevent this from occurring?</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.
 

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