想从帐户控制器AddPhoneNumber
页面的管理控制器中调用Login
方法。我已经为OTP实现了“登录”页面中的复选框。
选中此复选框后,它应从管理控制器调用AddPhoneNumber
GET
方法以打开页面。
但是它像这样http://localhost:49812/Account/Login?ReturnUrl=%2FManage%2FAddPhoneNumber
管理控制器
// GET: /Manage/AddPhoneNumber
public ActionResult AddPhoneNumber()
{
return View();
}
AddPhoneNumber页面
@model Aayumitra.Models.AddPhoneNumberViewModel
@using (Html.BeginForm("AddPhoneNumber", "Manage", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Add a phone number</h4>
<hr />
@Html.ValidationSummary("", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(m => m.Number, new { @class = "col-md-5 control-label" })
<div class="col-md-7">
@Html.TextBoxFor(m => m.Number, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-primary" value="Send verification code" />
</div>
</div>
}
登录页面
@using Aayumitra.Models
@model LoginViewModel
@using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<div class="form-group">
<label for="email">Mobile Number / Email ID</label>
@Html.TextBoxFor(m => m.Email, new { @class = "form-control form-control-sm", placeholder = "Mobile Number / Email ID" })
@Html.ValidationMessageFor(m => m.Email, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<label for="password">Password</label>
@Html.PasswordFor(m => m.Password, new { @class = "form-control form-control-sm password-input", placeholder = "Password" })
@Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<input type="checkbox" name="remember-password" id="remember-pass-check" onclick="triggerLink()">
<label for="">Login with OTP instead of password</label>
</div>
}
function triggerLink() {
debugger;
var theUrl = '@Url.Action("AddPhoneNumber", "Manage")';
$(location).attr('href', theUrl);
//window.location.href = theUrl;
};
[1]: https://i.stack.imgur.com/6RAXm.png
答案 0 :(得分:1)
您的js函数必须在
"script" tag
中声明
尝试一下:
<script>
$(document).ready(function(){
$("#remember-pass-check").change(function() {
if(this.checked) {
window.location.href ='@Url.Action("AddPhoneNumber", "Manage")';
}
});
});
</script>
答案 1 :(得分:0)
当我在解决方案中检查了视图页面和控制器操作代码时,我遇到了相同的问题。但是,我发现了问题所在,请重命名Manage controller
,然后进行检查。