你能帮我解决这个问题吗?我正在实现没有表单或 html.beginform 的登录表单,因为我正在通过 Ajax 调用调用控制器/API,并且基于状态消息/成功,我想根据要求重定向到某个页面。请注意,我不应该跳过已为控制器方法实施的防伪方法。谢谢。
但由于“所需的防伪表单字段 __RequestVerificationToken 不存在”,我无法继续进行
我的观点如下:
""<input data-bind="value: UserName" type="text" name="username" />
<button type="button" data-bind="click:LoginMethod"> Login </button>""
而Ajax代码如下
self.LoginMethod = function () {
//Ajax call to Insert the Customer record
$.ajax({
type: "POST",
url: "http://localhost:8089/Home/SignIn/",
data: ko.toJSON(CustData), //Convert the Observable Data into JSON
success: function (data) {
console.log("success");
alert("Record Added Successfully");
},
error: function () {
console.log("failed");
alert("Failed");
}
});
感谢您的帮助。