5
Reply

Can we have multiple forms in a View in ASP.NET MVC

Anupam Singh

Anupam Singh

10y
16.1k
1
Reply

    Yes we can, here is an example :// submit first form @using(BeginForm("Action","Controller",FormMethod.Post)) {@TextBox("txtBox1")}//submit second form @using(BeginForm("Action","Controller",FormMethod.Post)) {@TextBox("txtBox2")}

    you can have multiple forms in single View just give different View to each form But if you want to use Single View then it is change to have to check from which foam the submit button is clicked Simple by send Submit button name

    Yes we can have any number of forms in any HTML or web page.

    @model ViewModel@using (Html.BeginForm("Login", "ABCController", FormMethod.Post, new {})) {@Html.LabelFor(m => m.LoginUsername)@Html.TextBoxFor(m => m.LoginUsername)@Html.LabelFor(m => m.LoginPassword)@Html.TextBoxFor(m => m.LoginPassword)}@using (Html.BeginForm("UserRegister", "ABCController", FormMethod.Post, new {})) {@Html.LabelFor(m => m.RegisterFirstName)@Html.TextBoxFor(m => m.RegisterFirstName)@Html.LabelFor(m => m.RegisterLastName)@Html.TextBoxFor(m => m.RegisterLastName)@Html.LabelFor(m => m.RegisterUsername)@Html.TextBoxFor(m => m.RegisterUsername)@Html.LabelFor(m => m.RegisterPassword)@Html.TextBoxFor(m => m.RegisterPassword)In Controller you can Give a code Below[HttpPost] public ActionResult Login(ViewModel model) {//do your login code here }[HttpPost] public ActionResult UserRegister(ViewModel model) {//do your registration code here }

    It is not Possible having multiple view in same page in MVC