简体   繁体   中英

ASP.Net MVC Razor Dropdownlist with submit button postback

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 aa submit button to do a GET request?

Secondly, anyone have any good literature that would resemble some sort of API for razor?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM