我有一個表格中定義爲提交表單視圖到控制器
using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
這種形式我的形式視圖contins若干類型的按鈕輸入和按鈕的
<input type="submit" value="val1" name="action">
<input type="submit" value="val2" name="action">
<input type="submit" value="val3" name="action" />
<button class="button" type="submit" name="action" value="val4">Val4</button>
我有2個控制器,用於這種觀點
Public ActionResult form{
}
和
[HttpPost]
public ActionResult form(String button)
{
switch (actionType)
{
case "val1":
return RedirectToAction("AnotherView");
case "val2":
return RedirectToAction("AnotherView2");
default:
return RedirectToAction("AnotherView3");
}
}
但無論按鈕我點擊,我被重定向到主頁的形式定義
using (Html.BeginForm("Index", "Home",
我的問題是如何解決這個問題,我怎麼能肯定的是,這個帖子的方法,勢必我剛剛輸入了什麼?
無論動作值如何,都會進入編輯方式 – jpo
提交表單後是否出錯? – heriawan
沒有錯誤。它只是轉到我的控制器的action_name方法。順便說一句,你是什麼意思由action_name和控制器名稱在「使用(Html.BeginForm(」action_name「,」控制器名稱「...」。你的意思是action_name =方法名= form(對於我的例子)和controllername = HomeController這是我的表單方法的控制器的名稱)? – jpo