簡體   English   中英

帶有提交按鈕回發的ASP.Net MVC Razor Dropdownlist

[英]ASP.Net MVC Razor Dropdownlist with submit button postback

首先,我是ASP.NET MVC的新手,很難找到好的資源(API?)。 所以我的問題有兩個方面:

我想嘗試讓我的下拉列表不自動回發。 相反,我試圖讓下拉列表只是選擇一個項目,然后允許提交按鈕提交GET請求。

所以,如果我看的代碼示例如下所示:

 @using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "TheForm" })){
     @Html.DropDownList(
         "CategoryID", 
         (SelectList) ViewData["Categories"], 
         "--Select One--", 
         new{ onchange = "document.getElementById('TheForm').submit();" }
     ) 
 }

如何更改此項而不是提交一個提交按鈕來執行GET請求?

其次,任何人都有任何好的文獻,類似於剃須刀的某種API?

您只需要在表單中添加一個input type='submit'元素。 (當然,更改為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' />
}

至於API文檔,我認為MSDN引用盡可能接近。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM