Hello! I have an Asp.Net Core MVC application with authorization controller. I transferred the razor page code to the webixJS code, but it doesn’t work properly. The data is being transmitted, but there are a few points that I would like to clarify.
- When authorization is successful, RedirectToAction(returnUrl) occurs. How do I get a returnUrl in a POST request? And manually redirect “window.location.href = <…>”.
- Will there be a redirect when returning View(model) in post-version? The page is not being updated right now.
- The action method is marked with the [ValidateAntiForgeryToken] attribute. Error 400 occurs with it. It is not possible to change the controller code at this stage. How can this be fixed?
public class AccountController : Controller
{
public IActionResult Login(string returnUrl)
{
ViewBag.returnUrl = returnUrl;
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (/*login and password is correct*/)
{
return RedirectToAction(returnUrl ?? "/");
}
ModelState.AddModelError(nameof(LoginModel.Login), "Invalid login or password!");
}
return View(model);
}
}
WebixJS:
async function sendForm() {
let form = $$("auth_form");
if (form.validate()) {
webix.ajax().post("/Account/Login", form.getValues());
}
}