0

我是 MVC 的新手。

我的布局页面中有以下内容:

<div id="RunValidation">
        @using (Html.BeginForm("RunValidation", "Home"))
        {
            <table>
                <tr>
                    <td>
                        <input type="checkbox" name="chkFindDuplicates" value="chkFindDuplicates">Find Cards
                    </td>
                </tr>

                <tr>
                    <td>
                        <input type="checkbox" name="chkFindDuplicates" value="chkFindDuplicates">Find Duplicates
                    </td>
                </tr>

                <tr>
                    <td>
                        <input type="checkbox" name="chkFindSuspectVoucherAllocation" value="chkFindSuspectVoucherAllocation">Find Suspect Voucher Allocataion
                    </td>
                </tr>


                <tr>
                    <td></td>
                    <td>
                        <input type="submit" value="SubmitValidation" /></td>
                </tr>
            </table>
        }
    </div>

我的 HomeController 中有以下操作:

public ActionResult RunValidaton()
    {
        //determine which validations checks to run
        int x = 0;


        //call into middle tier to execute the validation

        return View();

    }

我的路线配置如下:

 public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }

当我单击我的 html 表单上的提交按钮时,我希望在 int x = 0; 上打一个断点;控制器中的行,但我收到 404 错误。

从 Fiddler 我可以在 Post 标题中看到以下内容:

POST /Home/RunValidation HTTP/1.1

我不明白为什么请求没有被路由到控制器?

4

2 回答 2

2

试试这个,

请更改您的操作方法名称。见下面的代码

<div id="RunValidation">
        @using (Html.BeginForm("Jeet", "Home", FormMethod.Post))
        {
            <table>
                <tr>
                    <td>
                        <input type="checkbox" name="chkFindDuplicates" value="chkFindDuplicates">Find Cards
                    </td>
                </tr>

                <tr>
                    <td>
                        <input type="checkbox" name="chkFindDuplicates" value="chkFindDuplicates">Find Duplicates
                    </td>
                </tr>

                <tr>
                    <td>
                        <input type="checkbox" name="chkFindSuspectVoucherAllocation" value="chkFindSuspectVoucherAllocation">Find Suspect Voucher Allocataion
                    </td>
                </tr>


                <tr>
                    <td></td>
                    <td>
                        <input type="submit" value="SubmitValidation" /></td>
                </tr>
            </table>
        }
    </div> 

    [HttpPost]
        public ActionResult Jeet()
        {

            //determine which validations checks to run
            int x = 0;


            //call into middle tier to execute the validation

            return View();

        }


 routes.MapRoute(
            name: "DefaultRunValidation",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Dashboard", action = "Jeet", id = UrlParameter.Optional }
        );
于 2013-07-25T11:10:11.227 回答
0

尝试使用 http 方法注释和操作参数创建操作。

[HttpPost]
public ActionResult RunValidaton(FormCollection form) //your model here would be better.
    {
        //determine which validations checks to run
        int x = 0;


        //call into middle tier to execute the validation

        return View();

    }
于 2013-07-25T11:14:16.143 回答