Here are two codes, help to compare, and with what is better to work?
1 Unobtrusive Ajax
@using (Ajax.BeginForm("Login", "Account", new AjaxOptions { HttpMethod = "Post", OnSuccess = "OnSuccess" })) { <div> <hr /> @Html.ValidationSummary() <div> @Html.TextBox("Email", "Введите E-mail") </div> <div> @Html.TextBox("Password", "Введите Password") </div> <div> <button id="buttonLogIn" type="submit">LOG IN</button> </div> </div> } <script type="text/javascript"> function OnSuccess(data) { //alert("Запрос был успешно выполнен. Получены следующие данные: \n" + data); var text = document.getElementById('UrlAddress').value; $(location).attr('href', text); } </script> 2 Ajax request to the form
@using (Html.BeginForm("Login", "Account", FormMethod.Post, new { id = "FormLogIn" })) { <div> <hr /> @Html.ValidationSummary() <div> @Html.TextBox("Email", "Введите E-mail") </div> <div> @Html.TextBox("Password", "Введите Password") </div> <div> <button id="buttonLogIn" type="submit">LOG IN</button> </div> </div> } <script> $(document).ready(function () { $("#buttonLogIn").on("click", function (e) { e.preventDefault(); $.ajax({ type: "POST", data: $("#FormLogIn").serialize(), url: '@Url.Action("Login", "Account")', success: function () { var text = document.getElementById('UrlAddress').value; $(location).attr('href', text); } }); }); }); </script> + I correctly understood that if I want ajax in any form, then the methods in the controllers should be normal, not asynchronous (async / await)?