我想在登录页面中选中复选框时调用管理控制器AddPhoneNumber
方法。我不确定如何调用该方法。
登录页面
@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)';
}
AddPhoneNumber.cshtml
@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>
}
管理控制器
// GET: /Manage/AddPhoneNumber
public ActionResult AddPhoneNumber()
{
return View();
}
答案 0 :(得分:-1)
<input type="checkbox" name="remember-password" id="remember-pass-check" onclick="customMethod()"}>
<script>
function customMethod() {
$.ajax({
url: "/Manage//AddPhoneNumber"
type: "POST",
dataType: "json",
data: {
model: '@Model'
}
});
}
</script>
并添加httpPost
[HttpPost]
public ActionResult AddPhoneNumber(AddPhoneNumberViewModel model)
{
return View();
}