1

我有多种形式的视图

@using (Html.BeginForm("Withdrawal", "ATMControl", FormMethod.Post, new {})) 
{
 //code   
}

@using (Html.BeginForm("Deposit", "ATMControl", FormMethod.Post, new {})) 
{
//code
}

@using (Html.BeginForm("transfer", "ATMControl", FormMethod.Post, new {})) 
{
//code
}

在我的控制器中:

//this works
 public ActionResult Index()
        {
                SetViewBagAccounts();
                return View();
        }

//this doesnt

        [HttpPost]
        public ActionResult Withdrawal(ATMModel model)
        {
            //do your login code here
            return View();
        }

我想做的是在这个控制器中单独处理提款、存款和转账。我不断收到此错误

无法找到该资源。

说明:HTTP 404。您要查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请查看以下 URL 并确保其拼写正确。

请求的 URL:/ATMControl/Withdrawal

4

3 回答 3

1

通过名称引用控制器时,不应包含名称的“控制器”部分。例如,如果您的控制器类被调用ATMController,那么您应该使用 just 来引用它"ATM",如下所示:

@using (Html.BeginForm("Withdrawal", "ATM", FormMethod.Post, new {})) 
{
}

这将转换为以下 URL:/ATM/Withdrawal

我目前无法找到一个链接来为您提供有关为什么以这种方式工作的更多信息,但是您应该知道 MVC 框架在确定哪个类是合适的时会隐式包含名称的“控制器”部分。

于 2013-09-26T09:46:42.027 回答
0

There is no problem using more than a Html.BeginForm() in a page.

Your code looks good, so if your controller is named ATMControlController you should not get a 404.

Try to use the BeginForm overload without the last argument, that is useless in that case.

Make also sure to build your project. It is a trivial suggestion, but it is a common mistake to save only the View (like in ASP.NET WebForms).

Please post more code for further help.

于 2013-09-26T09:32:21.433 回答
0

/ATM/Withdrawal/如果您的控制器名称准确,则使用ATMController,这意味着

RouteName + Controller =RouteNameController

then 

/RouteName/ActionName
于 2013-09-26T11:33:23.657 回答