2013-12-16 50 views
3

首先,我是ASP.NET MVC的新手,並且很難爲它找到好的資源(API?)。所以我的問題來了兩方面:ASP.Net MVC剃刀下拉列表提交按鈕回發

我想嘗試讓我的dropdownlist不自動回發。相反,我試圖讓dropdownlist只選擇一個項目,然後允許提交按鈕提交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的良好文獻?

回答

2

您只需在表單中添加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 reference是儘可能接近你會得到。