4

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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.