要在“帐户控制器登录页面”的“管理控制器”中调用AddPhoneNumber
方法。我已经为OTP实现了“登录”页面中的复选框。
我想要的是,当选中复选框时,它应该从管理控制器调用AddPhoneNumber
GET方法以打开页面。
管理控制器
// 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", Model)';
}
答案 0 :(得分:1)
请参阅:How do I redirect to another webpage?
在您的triggerLink()
方法中,类似:
<script type="text/javascript">
function triggerLink() {
debugger;
var theUrl ='@Url.Action("AddPhoneNumber","Manage")';
window.location.href = theUrl;
}
</script>
另外,不要认为您需要传递模型,因为您的控制器动作看起来并不像预期的那样……