Reputation: 413
First off, I am new to ASP.NET MVC and having a hard time finding good resources (API?) for it. So my question comes two-fold:
I want to try and get my dropdownlist to not auto-postback. Instead, I'm trying to get the dropdownlist to simply select an item, and then allow a submit button to submit the GET request.
So if the code example I am looking at looks like this:
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "TheForm" })){
@Html.DropDownList(
"CategoryID",
(SelectList) ViewData["Categories"],
"--Select One--",
new{ onchange = "document.getElementById('TheForm').submit();" }
)
}
how do I alter this to instead put a a submit button to do a GET request?
Secondly, anyone have any good literature that would resemble some sort of API for razor?
Upvotes: 4
Views: 9806
Reputation: 102793
You just have to add an input type='submit'
element to the form. (And of course, change to FormMethod.Get
.)
@using (Html.BeginForm("Index", "Home", FormMethod.Get, new { id = "TheForm" }))
{
@Html.DropDownList( "CategoryID",
(SelectList) ViewData["Categories"],
"--Select One--",
new{ onchange = "document.getElementById('TheForm').submit();" }
)
<input type='submit' value='Submit' />
}
As far as API documentation, I think the MSDN reference is as close as you will get.
Upvotes: 4