I have a Razor form
using (Html.BeginForm("TermList", "Course", FormMethod.Get))
{
<div style="text-align:right;display:inline-block; width:48%; margin-right:25px;">
@Html.DropDownList( "id", (SelectList) ViewBag.schoolId)
</div>
<input type="submit" value="Choose school" />
}
I expected this form to post to URI of:
http://localhost:56939/Course/TermList/764
instead the route looks like:
http://localhost:56939/Course/TermList?id=764
the route is not being used. I'd like to do away with the parameter
?id=764
The reason
?id=764
is appended to the URL is because you're usingFormMethod.Get
. Any values you are going to pass along with your form will be added in the querystring. You need to useFormMethod.Post
.This will result in a form action of
http://localhost:56939/Course/TermList/
If you want to post to
http://localhost:56939/Course/TermList/764
you need to pass theid
parameter in theHtml.BeginForm
statement:Obviously instead of hard coding
764
just use whatever variable it is that stores that value.