Validation does not work when using AJAX request [duplicate]
This question already has an answer here:
jQuery Validate SubmitHandler with Ajax Submission Not being hit
1 answer
Jquery post and unobtrusive ajax validation not working mvc 4
1 answer
I'm trying to validate fields with ValidationMessageFor
, and everything works fine if you submit the form using Html.Beginform
, but if I use an AJAX query, then validations no longer work.
My Code
View:
@model AutoStore.Domain.Core.Client
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<style>
html,
body {
height: 100%;
}
body {
display: -ms-flexbox;
display: flex;
-ms-flex-align: center;
align-items: center;
padding-top: 40px;
padding-bottom: 40px;
}
.form-signin {
width: 100%;
max-width: 330px;
padding: 15px;
margin: auto;
}
.input-group-text {
border-top-left-radius: 30px;
border-bottom-left-radius: 30px;
}
.form-control {
border-radius: 30px;
}
</style>
@Html.ActionLink("Главная", "Index")
@using (Html.BeginForm())
{
<div class="container">
<div class="form-signin">
<div class="form-group">
@Html.LabelFor(i => i.CSurname, "Фамилия")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-id-badge" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.CSurname, new { htmlAttributes = new { @id = "txtSurname", @class = "form-control", @placeholder = "Введите фамилию" } })
</div>
@Html.ValidationMessageFor(i => i.CSurname, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.CName, "Имя")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-id-badge" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.CName, new { htmlAttributes = new { @id = "txtName", @class = "form-control", @placeholder = "Введите имя" } })
</div>
@Html.ValidationMessageFor(i => i.CName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.CPatronymic, "Отчество")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-id-badge" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.CPatronymic, new { htmlAttributes = new { @id = "txtPatr", @class = "form-control", @placeholder = "Введите отчество" } })
</div>
@Html.ValidationMessageFor(i => i.CPatronymic, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.Login, "Логин")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-user fa" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.Login, new { htmlAttributes = new { @id = "txtLogin", @class = "form-control", @placeholder = "Введите логин" } })
</div>
@Html.ValidationMessageFor(i => i.Login, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.Password, "Пароль")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-lock fa" aria-hidden="true"></i></span>
@Html.PasswordFor(i => i.Password, new { @id = "txtPass", @class = "form-control", @placeholder = "Введите пароль" })
</div>
@Html.ValidationMessageFor(i => i.Password, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.Email, "E-Mail")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.Email, new { htmlAttributes = new { @id = "txtMail", @class = "form-control", @placeholder = "Введите e-mail", @type = "email" } })
</div>
@Html.ValidationMessageFor(i => i.Email, "", new { @class = "text-danger" })
</div>
</div>
<input id="btnAdd" type="submit" class="btn btn-success btn-block" value="Добавить" />
</div>
</div>
}
<script type="text/javascript">
$(document).ready(function () {
$('form').validate({
submitHandler: function (form) {
$.ajax({
type: "POST",
url: "/Authorization/Registration",
data: $(form).serialize(),
success: function (result) {
$(location).attr('href', result.URL);
}
});
}
});
});
Controller:
[HttpPost]
public ActionResult Registration(Client client)
{
if (ModelState.IsValid)
{
/*unitOfWork.Clients.Create(client);
unitOfWork.Save();*/
var url = new { URL = Url.Content("/Authorization/Index") + "#success" };
return Json(url);
}
return View();
}
_Layout:
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/scripts/jquery.unobtrusive-ajax.js")
@Scripts.Render("~/scripts/jquery.validate.min.js")
@Scripts.Render("~/scripts/jquery.validate.unobtrusive.min.js")
<div class="container body-content">
@RenderBody()
</div>
With this option validation works, but only after the form is submitted. And after performing the Ajax request, it does not redirect me to the address that I collect in the controller, but instead simply displays this address as a string on the screen. And if instead of using jquery Ajax.Beginform
, then, validation does not work when the form has already been submitted, but immediately after entering incorrect data in the input field.
jquery ajax asp.net-mvc jquery-validate unobtrusive-validation
marked as duplicate by Liam, Tetsuya Yamamoto, Sparky
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 4 at 18:08
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
|
show 6 more comments
This question already has an answer here:
jQuery Validate SubmitHandler with Ajax Submission Not being hit
1 answer
Jquery post and unobtrusive ajax validation not working mvc 4
1 answer
I'm trying to validate fields with ValidationMessageFor
, and everything works fine if you submit the form using Html.Beginform
, but if I use an AJAX query, then validations no longer work.
My Code
View:
@model AutoStore.Domain.Core.Client
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<style>
html,
body {
height: 100%;
}
body {
display: -ms-flexbox;
display: flex;
-ms-flex-align: center;
align-items: center;
padding-top: 40px;
padding-bottom: 40px;
}
.form-signin {
width: 100%;
max-width: 330px;
padding: 15px;
margin: auto;
}
.input-group-text {
border-top-left-radius: 30px;
border-bottom-left-radius: 30px;
}
.form-control {
border-radius: 30px;
}
</style>
@Html.ActionLink("Главная", "Index")
@using (Html.BeginForm())
{
<div class="container">
<div class="form-signin">
<div class="form-group">
@Html.LabelFor(i => i.CSurname, "Фамилия")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-id-badge" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.CSurname, new { htmlAttributes = new { @id = "txtSurname", @class = "form-control", @placeholder = "Введите фамилию" } })
</div>
@Html.ValidationMessageFor(i => i.CSurname, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.CName, "Имя")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-id-badge" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.CName, new { htmlAttributes = new { @id = "txtName", @class = "form-control", @placeholder = "Введите имя" } })
</div>
@Html.ValidationMessageFor(i => i.CName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.CPatronymic, "Отчество")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-id-badge" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.CPatronymic, new { htmlAttributes = new { @id = "txtPatr", @class = "form-control", @placeholder = "Введите отчество" } })
</div>
@Html.ValidationMessageFor(i => i.CPatronymic, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.Login, "Логин")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-user fa" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.Login, new { htmlAttributes = new { @id = "txtLogin", @class = "form-control", @placeholder = "Введите логин" } })
</div>
@Html.ValidationMessageFor(i => i.Login, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.Password, "Пароль")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-lock fa" aria-hidden="true"></i></span>
@Html.PasswordFor(i => i.Password, new { @id = "txtPass", @class = "form-control", @placeholder = "Введите пароль" })
</div>
@Html.ValidationMessageFor(i => i.Password, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.Email, "E-Mail")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.Email, new { htmlAttributes = new { @id = "txtMail", @class = "form-control", @placeholder = "Введите e-mail", @type = "email" } })
</div>
@Html.ValidationMessageFor(i => i.Email, "", new { @class = "text-danger" })
</div>
</div>
<input id="btnAdd" type="submit" class="btn btn-success btn-block" value="Добавить" />
</div>
</div>
}
<script type="text/javascript">
$(document).ready(function () {
$('form').validate({
submitHandler: function (form) {
$.ajax({
type: "POST",
url: "/Authorization/Registration",
data: $(form).serialize(),
success: function (result) {
$(location).attr('href', result.URL);
}
});
}
});
});
Controller:
[HttpPost]
public ActionResult Registration(Client client)
{
if (ModelState.IsValid)
{
/*unitOfWork.Clients.Create(client);
unitOfWork.Save();*/
var url = new { URL = Url.Content("/Authorization/Index") + "#success" };
return Json(url);
}
return View();
}
_Layout:
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/scripts/jquery.unobtrusive-ajax.js")
@Scripts.Render("~/scripts/jquery.validate.min.js")
@Scripts.Render("~/scripts/jquery.validate.unobtrusive.min.js")
<div class="container body-content">
@RenderBody()
</div>
With this option validation works, but only after the form is submitted. And after performing the Ajax request, it does not redirect me to the address that I collect in the controller, but instead simply displays this address as a string on the screen. And if instead of using jquery Ajax.Beginform
, then, validation does not work when the form has already been submitted, but immediately after entering incorrect data in the input field.
jquery ajax asp.net-mvc jquery-validate unobtrusive-validation
marked as duplicate by Liam, Tetsuya Yamamoto, Sparky
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 4 at 18:08
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
You need to usejQuery.validate
library as provided in this issue and set validation rules depending on requirements.
– Tetsuya Yamamoto
Jan 3 at 8:00
Try: stackoverflow.com/a/52208543/594235
– Sparky
Jan 5 at 19:35
@Sparky, i try it's, but not work. I give an example of my code at the end of the question.
– Андрей
Jan 6 at 16:29
@Sparky It turned out to make so that validation would work immediately when entering data into text fields. Forgot to add first$(document).ready
, but there was another problem. After performing the Ajax request, the program does not transfer to the page with the address I return to the controller, but simply writes this address as a string on the screen. The screenshot at the end of the question.
– Андрей
Jan 6 at 17:32
@Sparky And what is most interesting, in the debugging of the client, the code does not even enter the block of the succession. Then I decided to check on the serverRequest.IsAjaxRequest
and result 'false'. Why the server does not consider my request, Ajax request. And how to fix it? What's wrong with my code?
– Андрей
Jan 6 at 17:33
|
show 6 more comments
This question already has an answer here:
jQuery Validate SubmitHandler with Ajax Submission Not being hit
1 answer
Jquery post and unobtrusive ajax validation not working mvc 4
1 answer
I'm trying to validate fields with ValidationMessageFor
, and everything works fine if you submit the form using Html.Beginform
, but if I use an AJAX query, then validations no longer work.
My Code
View:
@model AutoStore.Domain.Core.Client
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<style>
html,
body {
height: 100%;
}
body {
display: -ms-flexbox;
display: flex;
-ms-flex-align: center;
align-items: center;
padding-top: 40px;
padding-bottom: 40px;
}
.form-signin {
width: 100%;
max-width: 330px;
padding: 15px;
margin: auto;
}
.input-group-text {
border-top-left-radius: 30px;
border-bottom-left-radius: 30px;
}
.form-control {
border-radius: 30px;
}
</style>
@Html.ActionLink("Главная", "Index")
@using (Html.BeginForm())
{
<div class="container">
<div class="form-signin">
<div class="form-group">
@Html.LabelFor(i => i.CSurname, "Фамилия")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-id-badge" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.CSurname, new { htmlAttributes = new { @id = "txtSurname", @class = "form-control", @placeholder = "Введите фамилию" } })
</div>
@Html.ValidationMessageFor(i => i.CSurname, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.CName, "Имя")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-id-badge" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.CName, new { htmlAttributes = new { @id = "txtName", @class = "form-control", @placeholder = "Введите имя" } })
</div>
@Html.ValidationMessageFor(i => i.CName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.CPatronymic, "Отчество")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-id-badge" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.CPatronymic, new { htmlAttributes = new { @id = "txtPatr", @class = "form-control", @placeholder = "Введите отчество" } })
</div>
@Html.ValidationMessageFor(i => i.CPatronymic, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.Login, "Логин")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-user fa" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.Login, new { htmlAttributes = new { @id = "txtLogin", @class = "form-control", @placeholder = "Введите логин" } })
</div>
@Html.ValidationMessageFor(i => i.Login, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.Password, "Пароль")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-lock fa" aria-hidden="true"></i></span>
@Html.PasswordFor(i => i.Password, new { @id = "txtPass", @class = "form-control", @placeholder = "Введите пароль" })
</div>
@Html.ValidationMessageFor(i => i.Password, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.Email, "E-Mail")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.Email, new { htmlAttributes = new { @id = "txtMail", @class = "form-control", @placeholder = "Введите e-mail", @type = "email" } })
</div>
@Html.ValidationMessageFor(i => i.Email, "", new { @class = "text-danger" })
</div>
</div>
<input id="btnAdd" type="submit" class="btn btn-success btn-block" value="Добавить" />
</div>
</div>
}
<script type="text/javascript">
$(document).ready(function () {
$('form').validate({
submitHandler: function (form) {
$.ajax({
type: "POST",
url: "/Authorization/Registration",
data: $(form).serialize(),
success: function (result) {
$(location).attr('href', result.URL);
}
});
}
});
});
Controller:
[HttpPost]
public ActionResult Registration(Client client)
{
if (ModelState.IsValid)
{
/*unitOfWork.Clients.Create(client);
unitOfWork.Save();*/
var url = new { URL = Url.Content("/Authorization/Index") + "#success" };
return Json(url);
}
return View();
}
_Layout:
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/scripts/jquery.unobtrusive-ajax.js")
@Scripts.Render("~/scripts/jquery.validate.min.js")
@Scripts.Render("~/scripts/jquery.validate.unobtrusive.min.js")
<div class="container body-content">
@RenderBody()
</div>
With this option validation works, but only after the form is submitted. And after performing the Ajax request, it does not redirect me to the address that I collect in the controller, but instead simply displays this address as a string on the screen. And if instead of using jquery Ajax.Beginform
, then, validation does not work when the form has already been submitted, but immediately after entering incorrect data in the input field.
jquery ajax asp.net-mvc jquery-validate unobtrusive-validation
This question already has an answer here:
jQuery Validate SubmitHandler with Ajax Submission Not being hit
1 answer
Jquery post and unobtrusive ajax validation not working mvc 4
1 answer
I'm trying to validate fields with ValidationMessageFor
, and everything works fine if you submit the form using Html.Beginform
, but if I use an AJAX query, then validations no longer work.
My Code
View:
@model AutoStore.Domain.Core.Client
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<style>
html,
body {
height: 100%;
}
body {
display: -ms-flexbox;
display: flex;
-ms-flex-align: center;
align-items: center;
padding-top: 40px;
padding-bottom: 40px;
}
.form-signin {
width: 100%;
max-width: 330px;
padding: 15px;
margin: auto;
}
.input-group-text {
border-top-left-radius: 30px;
border-bottom-left-radius: 30px;
}
.form-control {
border-radius: 30px;
}
</style>
@Html.ActionLink("Главная", "Index")
@using (Html.BeginForm())
{
<div class="container">
<div class="form-signin">
<div class="form-group">
@Html.LabelFor(i => i.CSurname, "Фамилия")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-id-badge" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.CSurname, new { htmlAttributes = new { @id = "txtSurname", @class = "form-control", @placeholder = "Введите фамилию" } })
</div>
@Html.ValidationMessageFor(i => i.CSurname, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.CName, "Имя")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-id-badge" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.CName, new { htmlAttributes = new { @id = "txtName", @class = "form-control", @placeholder = "Введите имя" } })
</div>
@Html.ValidationMessageFor(i => i.CName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.CPatronymic, "Отчество")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-id-badge" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.CPatronymic, new { htmlAttributes = new { @id = "txtPatr", @class = "form-control", @placeholder = "Введите отчество" } })
</div>
@Html.ValidationMessageFor(i => i.CPatronymic, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.Login, "Логин")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-user fa" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.Login, new { htmlAttributes = new { @id = "txtLogin", @class = "form-control", @placeholder = "Введите логин" } })
</div>
@Html.ValidationMessageFor(i => i.Login, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.Password, "Пароль")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-lock fa" aria-hidden="true"></i></span>
@Html.PasswordFor(i => i.Password, new { @id = "txtPass", @class = "form-control", @placeholder = "Введите пароль" })
</div>
@Html.ValidationMessageFor(i => i.Password, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(i => i.Email, "E-Mail")
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
@Html.EditorFor(i => i.Email, new { htmlAttributes = new { @id = "txtMail", @class = "form-control", @placeholder = "Введите e-mail", @type = "email" } })
</div>
@Html.ValidationMessageFor(i => i.Email, "", new { @class = "text-danger" })
</div>
</div>
<input id="btnAdd" type="submit" class="btn btn-success btn-block" value="Добавить" />
</div>
</div>
}
<script type="text/javascript">
$(document).ready(function () {
$('form').validate({
submitHandler: function (form) {
$.ajax({
type: "POST",
url: "/Authorization/Registration",
data: $(form).serialize(),
success: function (result) {
$(location).attr('href', result.URL);
}
});
}
});
});
Controller:
[HttpPost]
public ActionResult Registration(Client client)
{
if (ModelState.IsValid)
{
/*unitOfWork.Clients.Create(client);
unitOfWork.Save();*/
var url = new { URL = Url.Content("/Authorization/Index") + "#success" };
return Json(url);
}
return View();
}
_Layout:
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/scripts/jquery.unobtrusive-ajax.js")
@Scripts.Render("~/scripts/jquery.validate.min.js")
@Scripts.Render("~/scripts/jquery.validate.unobtrusive.min.js")
<div class="container body-content">
@RenderBody()
</div>
With this option validation works, but only after the form is submitted. And after performing the Ajax request, it does not redirect me to the address that I collect in the controller, but instead simply displays this address as a string on the screen. And if instead of using jquery Ajax.Beginform
, then, validation does not work when the form has already been submitted, but immediately after entering incorrect data in the input field.
This question already has an answer here:
jQuery Validate SubmitHandler with Ajax Submission Not being hit
1 answer
Jquery post and unobtrusive ajax validation not working mvc 4
1 answer
jquery ajax asp.net-mvc jquery-validate unobtrusive-validation
jquery ajax asp.net-mvc jquery-validate unobtrusive-validation
edited Jan 6 at 17:35
Андрей
asked Jan 3 at 7:52
АндрейАндрей
1135
1135
marked as duplicate by Liam, Tetsuya Yamamoto, Sparky
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 4 at 18:08
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Liam, Tetsuya Yamamoto, Sparky
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 4 at 18:08
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
You need to usejQuery.validate
library as provided in this issue and set validation rules depending on requirements.
– Tetsuya Yamamoto
Jan 3 at 8:00
Try: stackoverflow.com/a/52208543/594235
– Sparky
Jan 5 at 19:35
@Sparky, i try it's, but not work. I give an example of my code at the end of the question.
– Андрей
Jan 6 at 16:29
@Sparky It turned out to make so that validation would work immediately when entering data into text fields. Forgot to add first$(document).ready
, but there was another problem. After performing the Ajax request, the program does not transfer to the page with the address I return to the controller, but simply writes this address as a string on the screen. The screenshot at the end of the question.
– Андрей
Jan 6 at 17:32
@Sparky And what is most interesting, in the debugging of the client, the code does not even enter the block of the succession. Then I decided to check on the serverRequest.IsAjaxRequest
and result 'false'. Why the server does not consider my request, Ajax request. And how to fix it? What's wrong with my code?
– Андрей
Jan 6 at 17:33
|
show 6 more comments
You need to usejQuery.validate
library as provided in this issue and set validation rules depending on requirements.
– Tetsuya Yamamoto
Jan 3 at 8:00
Try: stackoverflow.com/a/52208543/594235
– Sparky
Jan 5 at 19:35
@Sparky, i try it's, but not work. I give an example of my code at the end of the question.
– Андрей
Jan 6 at 16:29
@Sparky It turned out to make so that validation would work immediately when entering data into text fields. Forgot to add first$(document).ready
, but there was another problem. After performing the Ajax request, the program does not transfer to the page with the address I return to the controller, but simply writes this address as a string on the screen. The screenshot at the end of the question.
– Андрей
Jan 6 at 17:32
@Sparky And what is most interesting, in the debugging of the client, the code does not even enter the block of the succession. Then I decided to check on the serverRequest.IsAjaxRequest
and result 'false'. Why the server does not consider my request, Ajax request. And how to fix it? What's wrong with my code?
– Андрей
Jan 6 at 17:33
You need to use
jQuery.validate
library as provided in this issue and set validation rules depending on requirements.– Tetsuya Yamamoto
Jan 3 at 8:00
You need to use
jQuery.validate
library as provided in this issue and set validation rules depending on requirements.– Tetsuya Yamamoto
Jan 3 at 8:00
Try: stackoverflow.com/a/52208543/594235
– Sparky
Jan 5 at 19:35
Try: stackoverflow.com/a/52208543/594235
– Sparky
Jan 5 at 19:35
@Sparky, i try it's, but not work. I give an example of my code at the end of the question.
– Андрей
Jan 6 at 16:29
@Sparky, i try it's, but not work. I give an example of my code at the end of the question.
– Андрей
Jan 6 at 16:29
@Sparky It turned out to make so that validation would work immediately when entering data into text fields. Forgot to add first
$(document).ready
, but there was another problem. After performing the Ajax request, the program does not transfer to the page with the address I return to the controller, but simply writes this address as a string on the screen. The screenshot at the end of the question.– Андрей
Jan 6 at 17:32
@Sparky It turned out to make so that validation would work immediately when entering data into text fields. Forgot to add first
$(document).ready
, but there was another problem. After performing the Ajax request, the program does not transfer to the page with the address I return to the controller, but simply writes this address as a string on the screen. The screenshot at the end of the question.– Андрей
Jan 6 at 17:32
@Sparky And what is most interesting, in the debugging of the client, the code does not even enter the block of the succession. Then I decided to check on the server
Request.IsAjaxRequest
and result 'false'. Why the server does not consider my request, Ajax request. And how to fix it? What's wrong with my code?– Андрей
Jan 6 at 17:33
@Sparky And what is most interesting, in the debugging of the client, the code does not even enter the block of the succession. Then I decided to check on the server
Request.IsAjaxRequest
and result 'false'. Why the server does not consider my request, Ajax request. And how to fix it? What's wrong with my code?– Андрей
Jan 6 at 17:33
|
show 6 more comments
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to use
jQuery.validate
library as provided in this issue and set validation rules depending on requirements.– Tetsuya Yamamoto
Jan 3 at 8:00
Try: stackoverflow.com/a/52208543/594235
– Sparky
Jan 5 at 19:35
@Sparky, i try it's, but not work. I give an example of my code at the end of the question.
– Андрей
Jan 6 at 16:29
@Sparky It turned out to make so that validation would work immediately when entering data into text fields. Forgot to add first
$(document).ready
, but there was another problem. After performing the Ajax request, the program does not transfer to the page with the address I return to the controller, but simply writes this address as a string on the screen. The screenshot at the end of the question.– Андрей
Jan 6 at 17:32
@Sparky And what is most interesting, in the debugging of the client, the code does not even enter the block of the succession. Then I decided to check on the server
Request.IsAjaxRequest
and result 'false'. Why the server does not consider my request, Ajax request. And how to fix it? What's wrong with my code?– Андрей
Jan 6 at 17:33