HttpPost ActionMethod不从ASP MVC中的视图调用 [英] HttpPost ActionMethod not calling from view in ASP MVC
问题描述
我的登录页面包含两个tab.One用于LogIn,另一个用于SignUp。
在我的LogInController中,我创建了三个动作方法,如下节所示。
< pre lang =c#> [HttpGet]
[ActionName( LogIn)]
public ActionResult LogIn()
{
return 查看() ;
}
[HttpPost]
[ActionName( LogIn )]
public ActionResult LogIn( string 电子邮件, string 密码)
{
// 部分代码
return RedirectToAction( LogIn , LogIn);
}
[HttpPost]
[ActionName( SignUp)]
public ActionResult SignUp( string 电子邮件,字符串密码)
{
// 某些代码
return RedirectToAction( SignUpWizard, SignUpWizard);
}
我的视图使用AJAX调用此Action方法.My View和AJAX调用如下所示。
<!DOCTYPE html>
< html>
< head>
< title>登录< / title>
< link href =〜/ Content / css / main.css =stylesheet/>
< link href =〜/ Content / plugins / bootstrap / css / bootstrap.min.css =stylesheet/>
< script src =〜/ Scripts / knockout-2.2.0.js>< / script>
< script src =〜/ Scripts / knockout-2.2.0.debug.js>< / script>
< script src =〜/ Content / js / jquery.js>< / script>
< script src =〜/ ViewModel / LoginViewModel.js>< / script>
< / head>
< body>
< nav class =navbar navbar-customrole =navigation>
< div class =container-fluid>
< h2 class =text-center t-size-change>登录< / h2>
< / div>
<! - /.container-fluid - >
< / nav>
< div class =container m-t-150>
< div class =row>
< div class =col-md-12>
< div class =login-tabs>
<! - 导航标签 - >
< ul class =nav nav-tabs nav-justified nav-tabs-customrole =tablist>
< li class =active>< a href =#homerole =tabdata-toggle =tab>登录< / a>< / li>
< li>< a href =#profilerole =tabdata-toggle =tab>免费注册< / a>< / li>
< / ul>
<! - Tab窗格 - >
< div class =tab-content>
< div class =tab-pane active custom-tabid =home>
< div class =row>
< div class =col-lg-12>
< div class =form-group>
< input type =emailplaceholder =Email Addressclass =form-controlname =Emailid =txtLogInEmailrequired>
< / div>
< div class =form-group>
< input type =passwordplaceholder =Passwordclass =form-controlname =Passwordid =txtLogInPasswordrequired>
< / div>
< input type =buttonvalue =登录Tucan Rotasclass =btn btn-success btn-customid =btnLogIn/>
< p class =text-center p-10>< a href =#>忘记密码?< / a>< / p>
< / div>
< / div>
< / div>
< div class =tab-pane custom-tabid =profile>
< div class =row>
< div class =col-lg-12>
< div class =form-group>
< input type =emailplaceholder =Email Addressclass =form-controlname =Emailid =txtSignUpEmailrequired>
< / div>
< div class =form-group>
< input type =passwordplaceholder =Passwordclass =form-controlname =Passwordid =txtSignUpPasswordrequired>
< / div>
< input type =buttonid =btnSignUpclass =btn btn-success btn-customvalue =免费注册/>
< / div>
< / div>
< / div>
< / div>
< / div>
< / div>
< / div>
< / div>
< script src =〜/ Content / plugins / bootstrap / js / bootstrap.min.js>< / script>
< script src =〜/ Content / js / tab.jstype =text / javascript>< / script>
< script>
$(function(){
$('#btnSignUp')。click(function(){
$ .ajax({
url:'@ Url.Action( SignUp,LogIn)',
方法:POST,
数据:{Email:$('#txtSignUpEmail')。val(),密码:$('#txtSignUpPassword')。 val()}
});
});
$('#btnLogIn')。click(function(){
$ .ajax({
url :'@ Url.Action(LogIn,LogIn)',
方法:POST,
数据:{电子邮件:$('#txtLogInEmail')。val(),密码: $('#txtLogInPassword')。val()}
});
});
});
< / script>
< / body>
< / html>
当我在SignUp或LogIn中输入EmailID和密码并单击SignUp或LogIn按钮时,Every时间它调用LogIn()方法用HttpGet属性装饰。但是这个相同的代码在不同的系统中正常工作。
(function(){
('#btnSignUp').click(function() {
.ajax({
url:'@ Url.Action(SignUp, LogIn)',
方法:POST,
数据:{电子邮件:
My login page contains two tab.One for LogIn and another for SignUp.
In my LogInController,I created three action method as shown in below section.
[HttpGet]
[ActionName("LogIn")]
public ActionResult LogIn()
{
return View();
}
[HttpPost]
[ActionName("LogIn")]
public ActionResult LogIn(string Email, string Password)
{
//Some code
return RedirectToAction("LogIn", "LogIn");
}
[HttpPost]
[ActionName("SignUp")]
public ActionResult SignUp(string Email,string Password)
{
//Some Code
return RedirectToAction("SignUpWizard", "SignUpWizard");
}
My view call this Action Method using AJAX.My View and AJAX call look like this.
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<link href="~/Content/css/main.css" rel="stylesheet" />
<link href="~/Content/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<script src="~/Scripts/knockout-2.2.0.js"></script>
<script src="~/Scripts/knockout-2.2.0.debug.js"></script>
<script src="~/Content/js/jquery.js"></script>
<script src="~/ViewModel/LoginViewModel.js"></script>
</head>
<body>
<nav class="navbar navbar-custom" role="navigation">
<div class="container-fluid">
<h2 class="text-center t-size-change">Login</h2>
</div>
<!-- /.container-fluid -->
</nav>
<div class="container m-t-150">
<div class="row">
<div class="col-md-12">
<div class="login-tabs">
<!-- Nav tabs -->
<ul class="nav nav-tabs nav-justified nav-tabs-custom" role="tablist">
<li class="active"><a href="#home" role="tab" data-toggle="tab">Login</a></li>
<li><a href="#profile" role="tab" data-toggle="tab">Sign up for free</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active custom-tab" id="home">
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<input type="email" placeholder="Email Address" class="form-control" name="Email" id="txtLogInEmail" required>
</div>
<div class="form-group">
<input type="password" placeholder="Password" class="form-control" name="Password" id="txtLogInPassword" required>
</div>
<input type="button" value="Login to Tucan Rotas" class="btn btn-success btn-custom" id="btnLogIn" />
<p class="text-center p-10"><a href="#">Forgot your password?</a></p>
</div>
</div>
</div>
<div class="tab-pane custom-tab" id="profile">
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<input type="email" placeholder="Email Address" class="form-control" name="Email" id="txtSignUpEmail" required>
</div>
<div class="form-group">
<input type="password" placeholder="Password" class="form-control" name="Password" id="txtSignUpPassword" required>
</div>
<input type="button" id="btnSignUp" class="btn btn-success btn-custom" value="Sign up for free" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="~/Content/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="~/Content/js/tab.js" type="text/javascript"></script>
<script>
$(function () {
$('#btnSignUp').click(function () {
$.ajax({
url:'@Url.Action("SignUp", "LogIn")',
method:"POST",
data: { Email: $('#txtSignUpEmail').val(), password: $('#txtSignUpPassword').val() }
});
});
$('#btnLogIn').click(function () {
$.ajax({
url: '@Url.Action("LogIn", "LogIn")',
method: "POST",
data: { Email: $('#txtLogInEmail').val(), password: $('#txtLogInPassword').val() }
});
});
});
</script>
</body>
</html>
When I enter EmailID and password in SignUp OR LogIn and click SignUp Or LogIn button, Every Time It call LogIn() method decorate with HttpGet Attribute.However This same code working properly in different System.
(function () {
('#btnSignUp').click(function () {
.ajax({ url:'@Url.Action("SignUp", "LogIn")', method:"POST", data: { Email:
这篇关于HttpPost ActionMethod不从ASP MVC中的视图调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!