0

我在调用控制器功能时遇到了一个小问题。奇怪的是,其他所有提交按钮都可以正常工作。但是这个有我现在无法解决的问题。我将向您展示两个带有提交按钮的表单,因为只有一个可以正常工作。

控制器:

public class MyController : Controller
{
    public ActionResult MethodOne()
        {
            ...
            return RedirectToAction("index");
        }

    public ActionResult MethodTwo()
        {
            ...
            return RedirectToAction("index");
        }
}

和观点:

//This one works fine!!
@using (Html.BeginForm("MethodOne", "My", FormMethod.Post))
{
    <input id="Some-cool-id" type="submit" value="Add!" />
}

//This one doesn't work?!
@using (Html.BeginForm("MethodTwo", "My", FormMethod.Post))
{
    <input id="some-cool-id2" type="submit" value="Delete"!" />
}

错误告诉 Method2 不在所需的路径中。

Resource not found.

Description: HTTP 404. Searched resource (or ...) ... 

Required path URL: /My/MethodTwo

我一直在寻找不好的地方,但最后,我需要帮助,谢谢。

4

2 回答 2

1

在方法之前添加属性[HttpPost]

于 2013-08-30T12:47:16.467 回答
0

尝试这个,

  @using (Html.BeginForm("MethodTwo", "Test", FormMethod.Post))
    {
        <input type="submit" value="asd" />
    }


     @using (Html.BeginForm("MethodOne", "Test", FormMethod.Post))
    {
        <input type="submit" value="poll" />
    }

控制器

 public class TestController : Controller
    {

 public ActionResult MethodOne()
        {

        return RedirectToAction("CustomerInfo");
    }

    public ActionResult MethodTwo()
    {

        return RedirectToAction("CustomerInfo");
    }

 [HttpGet]
        public ActionResult CustomerInfo()
        {

        ViewBag.CustomerNameID = new SelectList(List, "CustomerId", "customerName");
        ViewBag.RegisterItems = GetAllRegisterData();
        ViewData["SampleList"] = GetAllRegisterData();
        return View();
    }
}
于 2013-08-30T13:22:14.107 回答