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

Anupam Singh
Posted Jun 13, 2014, 12:00 AM EDT5 Answers
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
Ali SadaamPosted Feb 26, 2015, 9:22 PM EST
Yes we can have any number of forms in any HTML or web page.
Ritesh SharmaPosted Jul 26, 2014, 7:17 PM EDT
@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
}
Jagan MohanPosted Jul 16, 2014, 9:33 AM EDT
It is not Possible having multiple view in same page in MVC
Yogesh TyagiPosted Jul 3, 2014, 9:24 PM EDT
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")
}
Anupam SinghPosted Jul 1, 2014, 1:45 AM EDT


