Thomas
Thomas

Reputation: 34188

Posting data from view to controller in ASP.Net MVC

net mvc. i am not being able to send data from client side to controller. suppose i have one form. there is two sets of input controls. one set is for login and another set is for registration but both controls are in one form. without using JavaScript to post form how can i post data from view to controller. there would be two different function in controller named login & register.

there will be two buttons control name Login & register in same form. when user fill up login details and click on login button then login data will be post to controller and login action method will be called.

when user fill up registration details and click on register button then registration related data will be post to controller and register action menthod will be called.

please help me with sample code for view & controller. thanks

Upvotes: 0

Views: 897

Answers (1)

Fabio S
Fabio S

Reputation: 1122

Do the following (one form, one controller action):

VIEW:

[...]
<input type="submit" id="login" name="login" value="Login" />
<input type="submit" id="register" name="register" value="Register" />

CONTROLLER ACTION:

[HttpPost]
public ActionResult LoginRegister(MyModel myModel, string login, string register)
{
    if (login == null)
    {
        // Button "Register" clicked
        [...]
    }

    if (register == null)
    {
        // Button "Login" clicked
        [...]
    }

    [...]

}

Upvotes: 0

Related Questions