<p>I have an action like this:</p>

<pre><code>public class News : System.Web.Mvc.Controller
{
    public ActionResult Archive(int year)
    {
       / *** /
    }
}
</code></pre>

<p>With a route like this:</p>

<pre><code>routes.MapRoute(
           "News-Archive",                                              
           "News.mvc/Archive/{year}",                           
           new { controller = "News", action = "Archive" }
       );
</code></pre>

<p>The URL that I am on is:</p>

<pre><code>News.mvc/Archive/2008
</code></pre>

<p>I have a form on this page like this:</p>

<pre><code>&lt;form&gt;
    &lt;select name="year"&gt;
        &lt;option value="2007"&gt;2007&lt;/option&gt;
    &lt;/select&gt;
&lt;/form&gt;
</code></pre>

<p>Submitting the form should go to News.mvc/Archive/2007 if '2007' is selected in the form.</p>

<p>This requires the form 'action' attribute to be "News.mvc/Archive".</p>

<p>However, if I declare a form like this:</p>

<pre><code>&lt;form method="get" action="&lt;%=Url.RouteUrl("News-Archive")%&gt;"&gt;
</code></pre>

<p>it renders as:</p>

<pre><code>&lt;form method="get" action="/News.mvc/Archive/2008"&gt;
</code></pre>

<p>Can someone please let me know what I'm missing?</p>

[{'answer_id': 49197, 'author': 'Brad Wilson', 'author_id': 1554, 'author_profile': 'https://Stackoverflow.com/users/1554', 'pm_score': 3, 'selected': True, 'text': '<p>You have a couple problems, I think.</p>\n\n<p>First, your route doesn\'t have a default value for "year", so the URL "/News.mvc/Archive" is actually not valid for routing purposes.</p>\n\n<p>Second, you\'re expect form values to show up as route parameters, but that\'s not how HTML works. If you use a plain form with a select and a submit, your URLs will end up having "?year=2007" on the end of them. This is just how GET-method forms are designed to work in HTML.</p>\n\n<p>So you need to come to some conclusion about what\'s important.</p>\n\n<ul>\n<li>If you want the user to be able to select something from the dropdown and that changes the submission URL, then you\'re going to have to use Javascript to achieve this (by intercepting the form submit and formulating the correct URL).</li>\n<li>If you\'re okay with /News.mvc/Archive?year=2007 as your URL, then you should remove the {year} designator from the route entirely. You can still leave the "int year" parameter on your action, since form values will also populate action method parameters.</li>\n</ul>\n'}, {'answer_id': 49206, 'author': 'Matt Mitchell', 'author_id': 364, 'author_profile': 'https://Stackoverflow.com/users/364', 'pm_score': 0, 'selected': False, 'text': "<p>I think I've worked out why - the route includes {year} so the generated routes always will too..</p>\n\n<p>If anyone can confirm this?</p>\n"}, {'answer_id': 49223, 'author': 'Matt Mitchell', 'author_id': 364, 'author_profile': 'https://Stackoverflow.com/users/364', 'pm_score': 0, 'selected': False, 'text': '<p><strong>Solution</strong></p>\n\n<p>Okay here is the solution, (thanks to Brad for leading me there).</p>\n\n<p>1) Require default value in route:</p>\n\n<pre><code>routes.MapRoute(\n       "News-Archive",                                              \n       "News.mvc/Archive/{year}",                           \n       new { controller = "News", action = "Archive", year = 0 }\n   );\n</code></pre>\n\n<p>2) Add a redirect to parse GET parameters as though they are URL segments.</p>\n\n<pre><code>public ActionResult Archive(int year)\n{\n   if (!String.IsNullOrEmpty(Request["year"]))\n   {\n       return RedirectToAction("Archive", new { year = Request["year"] });\n   }\n}\n</code></pre>\n\n<p>3) Make sure you have your redirect code for Request params <em>before</em> any code for redirecting "default" year entries.  i.e.</p>\n\n<pre><code>public ActionResult Archive(int year)\n{\n   if (!String.IsNullOrEmpty(Request["year"]))\n   {\n       return RedirectToAction("Archive", new { year = Request["year"] });\n   }\n   if (year == 0)\n   {\n       /* ... */\n   }\n   /* ... */\n}\n</code></pre>\n\n<p>3) Explicitly specify the default value for year in the Url.RouteUrl() call:</p>\n\n<pre><code>Url.RouteUrl("News-Archive", new { year = 0 })\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/49194', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/364/']