问题描述
我在一个视图中有三个按钮,如果我提交第二个按钮,则表示没有提交。
请帮助我。
查看:
I have three buttons in one view and if i submit second button it's not submitting.
please help me.
View :
@model sb_admin_2.Web.Models.Account.LoginAuthontication
@using (Html.BeginForm("HomePage", "UserLoginhome", FormMethod.Post, null))
{
@Html.AntiForgeryToken()
<div class="row ml0 mr0 login-bg">
<div class="container">
<div class="col-md-4 login1">
<h3 class="h3 text-center">Corporate Login</h3>
<form class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div>
<span class="text-danger"> @TempData["CorparateError"] </span>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CorpLogin.CorpEmailId, new { @class = "control-label col-md-3", })
<div class="col-md-9">
@Html.EditorFor(model => model.CorpLogin.CorpEmailId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CorpLogin.CorpEmailId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CorpLogin.CorpPassword, new { @class = "control-label col-md-3", })
<div class="col-md-9">
@Html.EditorFor(model => model.CorpLogin.CorpPassword, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CorpLogin.CorpPassword, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-3 col-md-9">
<div class="checkbox">
@*<label><input type="checkbox"> Remember me</label>*@
@Html.CheckBoxFor(m => m.CorpLogin.CorpRemeberMe)
@Html.DisplayNameFor(m => m.CorpLogin.CorpRemeberMe)
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-3 col-md-9">
<button type="submit" class="btn btn-primary wide" name="Command" value="CorparateLogin">Login</button>
</div>
</div>
</form>
</div>
<div class="col-md-4 login1">
<h3 class="h3 text-center">Individual Login</h3>
<form class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div>
<span class="text-danger"> @TempData["IndividualError"]</span>
</div>
<div class="form-group">
@Html.LabelFor(model => model.IndLogin.IndEmailId, new { @class = "control-label col-md-3", })
<div class="col-md-9">
@Html.EditorFor(model => model.IndLogin.IndEmailId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.IndLogin.IndEmailId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.IndLogin.IndPassword, new { @class = "control-label col-md-3", })
<div class="col-md-9">
@Html.EditorFor(model => model.IndLogin.IndPassword, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.IndLogin.IndPassword, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-3 col-md-9">
<div class="checkbox">
@Html.CheckBoxFor(m => m.IndLogin.IndRemeberMe)
@Html.DisplayNameFor(m => m.IndLogin.IndRemeberMe)
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-3 col-md-9">
<button type="submit" class="btn btn-primary wide" name="Command" value="IndividualLogin">Login</button>
</div>
</div>
</form>
</div>
<div class="col-md-4 login1">
<h3 class="h3 text-center">Candidate Login</h3>
<form class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div>
<span class="text-danger"> @TempData["CandidateError"] </span>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CandLogin.CandUserId, new { @class = "control-label col-md-3", })
<div class="col-md-9">
@Html.EditorFor(model => model.CandLogin.CandUserId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CandLogin.CandUserId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CandLogin.CandPassword, new { @class = "control-label col-md-3", })
<div class="col-md-9">
@Html.EditorFor(model => model.CandLogin.CandPassword, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CandLogin.CandPassword, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-3 col-md-9">
<div class="checkbox">
@Html.CheckBoxFor(m => m.CandLogin.CandRemeberMe)
@Html.DisplayNameFor(m => m.CandLogin.CandRemeberMe)
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-3 col-md-9">
<button type="submit" class="btn btn-primary wide" name="Command" value="CandidateLogin">Login</button>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- Login form end -->
}
public ActionResult HomePage()
{
LoginAuthontication model = new LoginAuthontication();
ViewBag.message = Session["Message"];
return View(model);
}
[HttpPost]
public ActionResult HomePage(LoginAuthontication model, string Command)
{
if (Command == "CorparateLogin")
{
var corpLogin = db.ALOrganizationUsers.FirstOrDefault(m => m.UserEmailID == model.CorpLogin.CorpEmailId && m.UserPassword == model.CorpLogin.CorpPassword);
if (model.CorpLogin.CorpRemeberMe == true)
{
HttpCookie cookie = new HttpCookie("YourAppLogin");
cookie.Values.Add("username", corpLogin.UserEmailID);
cookie.Expires = DateTime.Now.AddDays(15);
Response.Cookies.Add(cookie);
}
if (corpLogin != null)
{
return RedirectToAction("Index", "UserLoginhome");
}
else
{
TempData["CorparateError"] = "Login data is incorrect";
// ModelState.AddModelError("", "Login data is incorrect!");
}
}
else if (Command == "IndividualLogin")
{
var indLogin = db.ALLoginIndividuals.FirstOrDefault(m => m.UserEmailID == model.IndLogin.IndEmailId && m.UserPassword == model.IndLogin.IndPassword);
if (model.IndLogin.IndRemeberMe == true)
{
HttpCookie cookie = new HttpCookie("YourAppLogin");
cookie.Values.Add("username", indLogin.UserEmailID);
cookie.Expires = DateTime.Now.AddDays(15);
Response.Cookies.Add(cookie);
}
if (indLogin != null)
{
return RedirectToAction("Index", "UserLoginhome");
}
else
{
TempData["IndividualError"] = "Login data is incorrect";
// ModelState.AddModelError("", "Login data is incorrect!");
}
}
else
{
var candLogin = db.ALUserDetails.FirstOrDefault(m => m.UserID == model.CandLogin.CandUserId && m.Pword == model.CandLogin.CandPassword);
//if (model.CorpRemeberMe == true)
//{
// HttpCookie cookie = new HttpCookie("YourAppLogin");
// cookie.Values.Add("userid", Convert.ToInt32(candLogin.UserID));
// cookie.Expires = DateTime.Now.AddDays(15);
// Response.Cookies.Add(cookie);
//}
if (candLogin != null)
{
//Session["TestId"] = model.TestId;
//Session["CompanyId"] = candLogin.CompanyID;
//Session["UserId"] = login.UserID;
return RedirectToAction("ALLBulkTestUserDetails", "UserLoginhome");
}
else
{
TempData["CandidateError"] = "Login data is incorrect";
//ModelState.AddModelError("", "Login data is incorrect!");
}
}
//}
return View();
}
public class LoginAuthontication
{
public CorprateLogin CorpLogin { get; set; }
public IndividualLogin IndLogin { get; set; }
public CandidateLogin CandLogin { get; set; }
}
public class CorprateLogin
{
[Required(ErrorMessage = "*Please Enter Email ID")]
[Display(Name = "Email ID")]
public string CorpEmailId { get; set; }
[Required(ErrorMessage = "*Please Enter Password")]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string CorpPassword { get; set; }
[Display(Name = "Remember me?")]
public bool CorpRemeberMe { get; set; }
}
public class IndividualLogin
{
[Required(ErrorMessage = "*Please Enter Email ID")]
[Display(Name = "Email ID")]
public string IndEmailId { get; set; }
[Required(ErrorMessage = "*Please Enter Password")]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string IndPassword { get; set; }
[Display(Name = "Remember me?")]
public bool IndRemeberMe { get; set; }
}
public class CandidateLogin
{
[Required(ErrorMessage = "*Please Enter Email ID")]
[Display(Name = "Email ID")]
public decimal CandUserId { get; set; }
[Required(ErrorMessage = "*Please Enter Password")]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string CandPassword { get; set; }
[Display(Name = "Remember me?")]
public bool CandRemeberMe { get; set; }
}
推荐答案
<form class="form-horizontal"></form>
and corresponding
and corresponding
from your code
from your code
@using (Html.BeginForm("HomePage", "UserLoginhome", FormMethod.Post, null))
will create tag for the generated HTML page. There can be only one form tag in ASP.Net html page
I have modefied the code and it is working
will create tag for the generated HTML page. There can be only one form tag in ASP.Net html page
I have modefied the code and it is working
<pre lang="c#">
@model WebApplication4.Models.LoginAuthontication
@using (Html.BeginForm(\"UserLoginhome\", \"Home\", FormMethod.Post))
{
@Html.AntiForgeryToken()
@model WebApplication4.Models.LoginAuthontication
@using (Html.BeginForm("UserLoginhome", "Home", FormMethod.Post))
{
@Html.AntiForgeryToken()
Corporate Login
Corporate Login
@Html.ValidationSummary(true, \"\", new { @class = \"text-danger\" })
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@TempData[\"CorparateError\"]
@TempData["CorparateError"]
@Html. LabelFor(model => model.CorpLogin.CorpEmailId, new { @class = \"control-label col-md-3\", })
@Html.LabelFor(model => model.CorpLogin.CorpEmailId, new { @class = "control-label col-md-3", })
@Html.EditorFor(model => model.CorpLogin.CorpEmailId, new { htmlAttributes = new { @class = \"form-control\" } })
@Html.ValidationMessageFor(model => model.CorpLogin.CorpEmailId, \"\", new { @class = \"text-danger\" })
@Html.EditorFor(model => model.CorpLogin.CorpEmailId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CorpLogin.CorpEmailId, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.CorpLogin.CorpPassword, new { @class = \"control-label col-md-3\", })
@Html.LabelFor(model => model.CorpLogin.CorpPassword, new { @class = "control-label col-md-3", })
@Html.EditorFor(model => model.CorpLogin.CorpPassword, new { htmlAttributes = new { @class = \"form-control\" } })
@Html.ValidationMessageFor(model =&g吨; model.CorpLogin.CorpPassword, \"\", new { @class = \"text-danger\" })
@Html.EditorFor(model => model.CorpLogin.CorpPassword, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CorpLogin.CorpPassword, "", new { @class = "text-danger" })
@*<label><input type=\"checkbox\"> Remember me</label>*@
@Html.CheckBoxFor(m => m.CorpLogin.CorpRemeberMe)
@Html.DisplayNameFor(m => m.CorpLogin.CorpRemeberMe)
@*<label><input type="checkbox"> Remember me</label>*@
@Html.CheckBoxFor(m => m.CorpLogin.CorpRemeberMe)
@Html.DisplayNameFor(m => m.CorpLogin.CorpRemeberMe)
<button type=\"submit\" class=\"btn btn-primary wide\" name=\"Command\" value=\"CorparateLogin\">Login</button>
<button type="submit" class="btn btn-primary wide" name="Command" value="CorparateLogin">Login</button>
Individual Login
Individual Login
@Html.ValidationSummary(true, \"\", new { @class = \"text-danger\" })
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@TempData[\"IndividualError\"]
@TempData["IndividualError"]
@Html.LabelFor(model => model.IndLogin.IndEmailId, new { @class = \"control-label col-md-3\", })
@Html.LabelFor(model => model.IndLogin.IndEmailId, new { @class = "control-label col-md-3", })
@Html.EditorFor(model => model.IndLogin.IndEmailId, new { htmlAttributes = new { @class = \"form-control\" } })
@Html.ValidationMessageFor(model => model.IndLogin.IndEmailId, \"\", new { @class = \"text-danger\" })
@Html.EditorFor(model => model.IndLogin.IndEmailId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.IndLogin.IndEmailId, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.IndLogin.IndPassword, new { @class = \"control-label col-md-3\", })
@Html.LabelFor(model => model.IndLogin.IndPassword, new { @class = "control-label col-md-3", })
@Html.EditorFor(model => model.IndLogin.IndPassword, new { htmlAttributes = new { @class = \"form-control\" } })
@Html.ValidationMessageFor(model => model.I ndLogin.IndPassword, \"\", new { @class = \"text-danger\" })
@Html.EditorFor(model => model.IndLogin.IndPassword, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.IndLogin.IndPassword, "", new { @class = "text-danger" })
@Html.CheckBoxFor(m => m.IndLogin.IndRemeberMe)
@Html.DisplayNameFor(m => m.IndLogin.IndRemeberMe)
@Html.CheckBoxFor(m => m.IndLogin.IndRemeberMe)
@Html.DisplayNameFor(m => m.IndLogin.IndRemeberMe)
<button type=\"submit\" class=\"btn btn-primary wide\" name=\"Command\" value=\"IndividualLogin\">Login</button>
<button type="submit" class="btn btn-primary wide" name="Command" value="IndividualLogin">Login</button>
Candidate Login
Candidate Login
@Html.ValidationSummary(true, \"\", new { @class = \"text-danger\" })
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@TempData[\"CandidateError\"]
@TempData["CandidateError"]
@Html.LabelFor(model => model.CandLogin.CandUserId, new { @class = \"control-label col-md-3\", })
@Html.LabelFor(model => model.CandLogin.CandUserId, new { @class = "control-label col-md-3", })
@Html.EditorFor(model => model.CandLogin.CandUserId, new { htmlAttributes = new { @class = \"form-control\" } })
@Html.ValidationMessageFor(model => model.CandLogin.CandUserId, \"\", new { @class = \"text-danger\" })
@Html.EditorFor(model => model.CandLogin.CandUserId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CandLogin.CandUserId, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.CandLogin.CandPassword, new { @class = \"control-label col-md-3\", })
@Html.LabelFor(model => model.CandLogin.CandPassword, new { @class = "control-label col-md-3", })
@Html.EditorFor(model => model.CandLogin.CandPassword, new { htmlAttributes = new { @class = \"form-control\" } })
@Html.ValidationMessageFor(model => model.CandLogin.CandPassword, \"\", new { @class = \"text-danger\" })
@Html.EditorFor(model => model.CandLogin.CandPassword, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CandLogin.CandPassword, "", new { @class = "text-danger" })
@Html.CheckBoxFor(m => m.CandLogin.CandRemeberMe)
@Html.DisplayNameFor(m => m.CandLogin.CandRemeberMe)
@Html.CheckBoxFor(m => m.CandLogin.CandRemeberMe)
@Html.DisplayNameFor(m => m.CandLogin.CandRemeberMe)
<button type=\"submit\" class=\"btn btn-primary wide\" name=\"Command\" value=\"CandidateLogin\">Login</button>
<button type="submit" class="btn btn-primary wide" name="Command" value="CandidateLogin">Login</button>
}
}
这篇关于多个提交按钮问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!