Note that there are some explanatory texts on larger screens.

plurals
  1. POGET Request Route Parameters
    primarykey
    data
    text
    <p>A standard <code>ActionLink</code> would produce something like mysite.com/rar/hello/1/2010-01-01/ if you wanted it to use route magic. This is fine for anchor tags and using <code>Html.ActionLink</code>, however, what if I wanted to have a form using a GET request to have the same effect? So a form looking like the following:</p> <pre><code>@using(Html.BeginForm("MyAction", "MyController", new { id = 20, something = "2010-01-01" })) </code></pre> <p>Yielding a URL like site.com/20/2010-01-01 instead of mysite.com?id=20&amp;something=2010-01-01</p> <p>Can this be done without using javascript? My routes are correct because <code>ActionLink</code>s generate the correct URL, but with the same parameters a GET request through a form generates the ugly URL.</p> <p>Cheers</p> <p><strong>--- EDIT ---</strong></p> <p>I did a search in Google for this same problem, and guess what? This answer is the first one. I hadn't even remembered asking it.</p> <p>So I've come across the same problem again. It's as simple as this:</p> <p>I click on a link, it takes me to a URL like <code>site.com/10/100/Param</code>. I have a form with these same route values that looks something like this:</p> <pre><code>@using(Html.BeginForm("Action", "Controller", FormMethod.Get)) { @Html.Hidden("param1", 10) @Html.Hidden("param2", 110) @Html.Hidden("param3", "MyOtherParam") } </code></pre> <p>Then when I submit this form, I expect to see the new route as <code>site.com/10/110/MyOtherParam</code> instead.</p> <p>The only way I can think of doing it is POSTing to an action method and then redirecting from there.</p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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