I have tried to make a form in a cshtml file send parameters to a function called "AddNewUser" inside a Controller I've named "AccountController".
Inside SignUp.cshtml I used the method Html.BeginForm like so:
@using (Html.BeginForm("AddNewUser", "Account", FormMethod.Post)){
}
Inside AccountContrller.cs I have the function AddNewUser whose header is:
[HttpPost]
public ActionResult AddNewUser(SignUpViewModel model)
Here is the directory tree, showing the locations of both files: directory tree
And here is the I get when I press send on the form in SignUp.cshtml: Error


In the picture of your directory tree you highlight a view called
SignUp. But if you read the picture of your error message you'll see that it's looking for a view calledAddNewUser. Which matches the name of your controller action:So presumably your controller action is trying to return a view. And that view doesn't exist.
You'd either need to create that view, or don't return a view from that controller action. You can instead return a redirect to another action. For example, if you want the user to be redirected to
SignUpafter the form is posted then you'd redirect them:Alternatively, you can return that view if you rename the controller action:
(And of course update the
BeginFormcall to reflect the new action method name.)This is common practice for handling form posts where you might want to re-display the form in the event of an error. Both the GET and the POST action methods can have the same name as long as the method signatures are different. (Which they should be, since the GET action would have no reason to accept a
SignUpViewModel.)That way the POST action can return the view for the user to try again. The general flow for a form POST action would be to return the view to the user in the event of an error, or redirect the user in the event of success.
You might find that you can also specify the view name explicitly when it doesn't match the controller action name:
While this is technically allowed, I highly discourage it unless you really know what you're doing in terms of HTTP actions and routes and RESTfulness, etc. Because the URL in the browser would still be
AddNewUser, notSignUp. This can cause other problems and weird bugs down the road.