当前位置: 动力学知识库 > 问答 > 编程问答 >

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

网友答案:

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
        [...]
    }

    [...]

}
分享给朋友:
您可能感兴趣的文章:
随机阅读: