如何获得控制器的按钮值?

use*_*351 7 c# asp.net-mvc

我有视图,它有两个按钮,分别是'是'和'否'.如果我点击"是"重定向一个页面,如果我点击"否"重定向到另一个页面.

这是我的观点.

@using (Html.BeginForm())
 { 
<table  >
 <tr>
    <td >
      Ceremony : 
    </td>
    <td>
       Ceremony at @Model.ceremony_date

    </td>
</tr>

  <tr>
            <td >
              Name :
            </td>
            <td >
               @Model.first_name  @Model.middle_name  @Model.last_name
            </td>
        </tr>
        <tr>
         <td colspan="2" >
            @Html.Partial("_DegreeDetailsByGraduand", @Model.DegreeList)
         </td>
        </tr>

        <tr>
        <td colspan="2" >
        IS information is correct ?
        </tr>
        <tr>
        <td>
         <input type="submit" id="btndegreeconfirmYes" name="btnsearch" class="searchbutton"  value="Yes" />    
         </td>  <td>
          <input type="submit" id="btndegreeconfirmNo" name="btnsearch" class="searchbutton"  value="No" /></td>  
        </tr>
</table>


 }
Run Code Online (Sandbox Code Playgroud)

这是我的控制器

[HttpPost]

        public ActionResult CheckData()
        {

            return RedirectToRoute("detailform");
        }
Run Code Online (Sandbox Code Playgroud)

我不知道如何获得控制器中的按钮值.我该怎么做.

Moh*_*han 8

为提交按钮指定名称,然后在控制器方法中检查提交的值:

<% Html.BeginForm("MyAction", "MyController", FormMethod.Post); %>
<input type="submit" name="submitButton" value="Send" />
<input type="submit" name="submitButton" value="Cancel" />
<% Html.EndForm(); %>



public class MyController : Controller {
    public ActionResult MyAction(string submitButton) {
        switch(submitButton) {
            case "Send":
                // delegate sending to another controller action

            case "Cancel":
                // call another action to perform the cancellation

            default:
                // If they've submitted the form without a submitButton, 
                // just return the view again.
                return(View());
        }
    }
Run Code Online (Sandbox Code Playgroud)

}

希望这可以帮助: