-1
我已經在stackoverflow和google上搜索過,並且發現了很多關於這個主題的文章,但是我仍然無法知道我做錯了什麼!我真的很絕望。例如。 How to handle two submit buttons on MVC view一個表格上的多個按鈕
我只是想在我看來有三個按鈕。我確實在控制器中執行了操作,但是,字符串比較不起作用。出於某種原因,我無法打破我的斷點。
這裏是我的代碼: 查看:
@using RequestDB7mvc.Models
@model MainViewModel
@{
ViewBag.Title = "Main";
}
<div class="form-group">
@using (Html.BeginForm("Search4", "Requests", FormMethod.Post))
{
<input type="submit" value="Save" name="command" />
<input type="submit" value="Done" name="command" />
<input type="submit" value="Cancel" name="command" />
}
控制器:
[HttpPost]
public ActionResult Search4(MainViewModel model, string command)
{
if (command.Equals("Save"))
{
// Call action here...
string f = "break";
}
else if (command.Equals("Done"))
{
// Call another action here...
string f = "break";
}
else if (command.Equals("Cancel"))
{
// Call another action here...
string f = "break";
}
ViewBag.Msg = "Details saved successfully.";
return View();
}
你嘗試和調試,以你都在行動命令參數得到。如果你不能擊中斷點,請嘗試寫入以跟蹤並驗證 – Shahzad
我確實嘗試過。我看到命令值,例如「取消」。但是,它不會跳轉到if語句中:-( – Nearshore
嘗試command.Equals(「Cancel」,StringComparison.InvariantCulture) – Shahzad