yellephen
yellephen

Reputation: 129

HTML.BeginForm not Routing to Controller Method

I'm writing an MVC website in C# with razor syntax.

I have some code here:

@using (Html.BeginForm("DoSignUp", "SignUpController", FormMethod.Post)) 
{
    <input type="text" width="3000" value="" name="Name" />
    <input type="submit" value="Register" /
}

So this form should post to the SignUpController on the DoSignUp method. Instead of doing that it just posts back to the page I'm currently on which is called SignUp. I suspected there might be something wrong with my routing but when I look at the html that is being generated through the browser developer tools i see this:

<form action="" method="post">        
    <input type="text" width="3000" value="" name="selectedURL">
    <input type="submit" value="Register">
</form>

Edit: Well I wrote this out and then looked at my code again. The problem which I keep bloody doing is that SignUpController should just be SignUp.

Upvotes: 1

Views: 240

Answers (1)

Daniel Mohr
Daniel Mohr

Reputation: 714

Remove the 'Controller' from your controller name (SignUp, not SignUpController). It's assumed to be a controller by convention

@using (Html.BeginForm("DoSignUp", "SignUp", FormMethod.Post)) 
{
    <input type="text" width="3000" value="" name="Name" />
    <input type="submit" value="Register" /
}

Upvotes: 2

Related Questions