How do I refer to a constant URL in my route configuration?

Posted by Remnant on Stack Overflow See other posts from Stack Overflow or by Remnant
Published on 2010-05-09T13:43:10Z Indexed on 2010/05/13 14:04 UTC
Read the original article Hit count: 456

Filed under:
|

Suppose I have the following within a webpage

<% using (Html.BeginForm("ShowData", "Summary")) %>
<% { %>
<div class="dropdown"><%=Html.DropDownList("CourseSelection", Model.CourseList, new { @class = "dropdown",  onchange="this.form.submit();" })%> </div>
<% } %>

When the user makes a selection from the dropdown the form is submitted and I would like it to link to another page with a URL as follows:

http://localhost:1721/Summary

I have the following routes:

    routes.MapRoute(null, "Summary", new { controller = "Summary", action = "ShowData", CourseSelection = (string) null });

    routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Login", action = "Index", id = UrlParameter.Optional });

When a user selects an item in the dropdownlist, the URL returned is:

http://localhost:1721/Summary/ShowData?CourseSelection = UserSelection

Clearly the first route in the list is not being matched.

I don't want the URL to show the action name and parameter. I simply want to show "Summary" which is what I have hard coded in the URL. How do I achieve this?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about routing