2011-03-29 18 views
1

hi 我在我的控制器中有一個actionresult索引方法,而對於同一個名稱有一個http post方法。當我運行程序時,控件應該轉到http post方法,但默認情況下它會轉到索引方法。將按鈕控制傳遞給http post方法

public ActionResult Index() 
{ 
    //code goes here 
} 

[HttpPost] 
public ActionResult Index(FormCollection form) 
{ 
} 

有人可以告訴我該怎麼做嗎?

+0

請您從您的視圖/形式提供一些代碼呢? – 2011-03-29 13:29:01

回答

1

默認情況下,它將轉到Index方法。如果你想調用[HttpPost]索引方法,你必須從表單中調用它,例如

<% using (Html.BeginForm("Index")) 
{ %> 
    <input type="text" name="someField" /> 
    <input type="submit" value="Save" /> 
<% } %> 

或使用Ajax.BeginForm與AjaxOption列舉HTTPMethod設置爲「POST」

相關問題