Reputation: 778
I have a view with multiple forms
@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
}
in my controller:
//this works
public ActionResult Index()
{
SetViewBagAccounts();
return View();
}
//this doesnt
[HttpPost]
public ActionResult Withdrawal(ATMModel model)
{
//do your login code here
return View();
}
what i am trying to do is process withdrawal, deposit and transfer indiviually in this controller. i keep getting this error
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /ATMControl/Withdrawal
Upvotes: 1
Views: 107
Reputation: 22619
use /ATM/Withdrawal/
if your controller name is exactly ATMController
, which mean
RouteName + Controller =RouteNameController
then
/RouteName/ActionName
Upvotes: 0
Reputation: 48415
When referencing a controller by it's name, you should not include the "Controller" part of the name. For example, if your controller class is called ATMController
, then you should reference it using just "ATM"
, like this:
@using (Html.BeginForm("Withdrawal", "ATM", FormMethod.Post, new {}))
{
}
This will translate to the following URL: /ATM/Withdrawal
I cannot find a link at the moment to povide you with more information about why this works this way, but you should be aware that the MVC framework will implicitly include the "Controller" part of the name when determining which class is appropriate.
Upvotes: 1
Reputation: 1022
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.
Upvotes: 0