Validation of the form with Ajax request












0















I am trying to validate the input field form. Achieved some results. I use Ajax request.
Model:



public int Id { get; set; }
[Required]
[Display(Name = "Фамилия")]
public string CSurname { get; set; }
[Required]
[Display(Name = "Имя")]
public string CName { get; set; }
[Required]
[Display(Name = "Отчество")]
public string CPatronymic { get; set; }
[Required]
[Display(Name = "Логин")]
public string Login { get; set; }
[Required]
[Display(Name = "Пароль")]
public string Password { get; set; }
[Required]
[Display(Name = "E-meil")]
public string Email { get; set; }

public virtual ICollection<Order> Orders { get; set; }

public Client()
{
Orders = new List<Order>();
}


Controller:



[HttpPost]
public ActionResult Registration(Client client)
{
if (ModelState.IsValid)
{
return RedirectToAction("Index");
}

return View();
}


View:



@using (Ajax.BeginForm("Registration", new AjaxOptions { UpdateTargetId = "results" }))
{
<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", @id = "mess" })
</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>
}


Also the scripts are connected to the layout.



@Scripts.Render("~/scripts/jquery.validate.min.js")
@Scripts.Render("~/scripts/jquery.validate.unobtrusive.min.js")


There is an email type field.
As soon as I start to enter data into it, if you do not enter @ then the message immediately pops out:
enter image description here



But, if i use Ajax.Beginform without connection



@Scripts.Render("~/scripts/jquery.validate.min.js")
@Scripts.Render("~/scripts/jquery.validate.unobtrusive.min.js")


When you click add, сlimbs another message in a different style.



enter image description here



This text contained in:



$('#txtMail')[0].validationMessage


How to me to achieve that when using Ajax of the request the same message?










share|improve this question

























  • Can you provide model class (including data annotations), controller action and corresponding scripts related to client-side validation message? I tried to create this fiddle with your current setup but still not understand the problem.

    – Tetsuya Yamamoto
    Jan 4 at 2:41











  • @TetsuyaYamamoto I described in the question in more detail everything you asked for. If there are any other questions, write.

    – Андрей
    Jan 4 at 6:49
















0















I am trying to validate the input field form. Achieved some results. I use Ajax request.
Model:



public int Id { get; set; }
[Required]
[Display(Name = "Фамилия")]
public string CSurname { get; set; }
[Required]
[Display(Name = "Имя")]
public string CName { get; set; }
[Required]
[Display(Name = "Отчество")]
public string CPatronymic { get; set; }
[Required]
[Display(Name = "Логин")]
public string Login { get; set; }
[Required]
[Display(Name = "Пароль")]
public string Password { get; set; }
[Required]
[Display(Name = "E-meil")]
public string Email { get; set; }

public virtual ICollection<Order> Orders { get; set; }

public Client()
{
Orders = new List<Order>();
}


Controller:



[HttpPost]
public ActionResult Registration(Client client)
{
if (ModelState.IsValid)
{
return RedirectToAction("Index");
}

return View();
}


View:



@using (Ajax.BeginForm("Registration", new AjaxOptions { UpdateTargetId = "results" }))
{
<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", @id = "mess" })
</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>
}


Also the scripts are connected to the layout.



@Scripts.Render("~/scripts/jquery.validate.min.js")
@Scripts.Render("~/scripts/jquery.validate.unobtrusive.min.js")


There is an email type field.
As soon as I start to enter data into it, if you do not enter @ then the message immediately pops out:
enter image description here



But, if i use Ajax.Beginform without connection



@Scripts.Render("~/scripts/jquery.validate.min.js")
@Scripts.Render("~/scripts/jquery.validate.unobtrusive.min.js")


When you click add, сlimbs another message in a different style.



enter image description here



This text contained in:



$('#txtMail')[0].validationMessage


How to me to achieve that when using Ajax of the request the same message?










share|improve this question

























  • Can you provide model class (including data annotations), controller action and corresponding scripts related to client-side validation message? I tried to create this fiddle with your current setup but still not understand the problem.

    – Tetsuya Yamamoto
    Jan 4 at 2:41











  • @TetsuyaYamamoto I described in the question in more detail everything you asked for. If there are any other questions, write.

    – Андрей
    Jan 4 at 6:49














0












0








0








I am trying to validate the input field form. Achieved some results. I use Ajax request.
Model:



public int Id { get; set; }
[Required]
[Display(Name = "Фамилия")]
public string CSurname { get; set; }
[Required]
[Display(Name = "Имя")]
public string CName { get; set; }
[Required]
[Display(Name = "Отчество")]
public string CPatronymic { get; set; }
[Required]
[Display(Name = "Логин")]
public string Login { get; set; }
[Required]
[Display(Name = "Пароль")]
public string Password { get; set; }
[Required]
[Display(Name = "E-meil")]
public string Email { get; set; }

public virtual ICollection<Order> Orders { get; set; }

public Client()
{
Orders = new List<Order>();
}


Controller:



[HttpPost]
public ActionResult Registration(Client client)
{
if (ModelState.IsValid)
{
return RedirectToAction("Index");
}

return View();
}


View:



@using (Ajax.BeginForm("Registration", new AjaxOptions { UpdateTargetId = "results" }))
{
<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", @id = "mess" })
</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>
}


Also the scripts are connected to the layout.



@Scripts.Render("~/scripts/jquery.validate.min.js")
@Scripts.Render("~/scripts/jquery.validate.unobtrusive.min.js")


There is an email type field.
As soon as I start to enter data into it, if you do not enter @ then the message immediately pops out:
enter image description here



But, if i use Ajax.Beginform without connection



@Scripts.Render("~/scripts/jquery.validate.min.js")
@Scripts.Render("~/scripts/jquery.validate.unobtrusive.min.js")


When you click add, сlimbs another message in a different style.



enter image description here



This text contained in:



$('#txtMail')[0].validationMessage


How to me to achieve that when using Ajax of the request the same message?










share|improve this question
















I am trying to validate the input field form. Achieved some results. I use Ajax request.
Model:



public int Id { get; set; }
[Required]
[Display(Name = "Фамилия")]
public string CSurname { get; set; }
[Required]
[Display(Name = "Имя")]
public string CName { get; set; }
[Required]
[Display(Name = "Отчество")]
public string CPatronymic { get; set; }
[Required]
[Display(Name = "Логин")]
public string Login { get; set; }
[Required]
[Display(Name = "Пароль")]
public string Password { get; set; }
[Required]
[Display(Name = "E-meil")]
public string Email { get; set; }

public virtual ICollection<Order> Orders { get; set; }

public Client()
{
Orders = new List<Order>();
}


Controller:



[HttpPost]
public ActionResult Registration(Client client)
{
if (ModelState.IsValid)
{
return RedirectToAction("Index");
}

return View();
}


View:



@using (Ajax.BeginForm("Registration", new AjaxOptions { UpdateTargetId = "results" }))
{
<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", @id = "mess" })
</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>
}


Also the scripts are connected to the layout.



@Scripts.Render("~/scripts/jquery.validate.min.js")
@Scripts.Render("~/scripts/jquery.validate.unobtrusive.min.js")


There is an email type field.
As soon as I start to enter data into it, if you do not enter @ then the message immediately pops out:
enter image description here



But, if i use Ajax.Beginform without connection



@Scripts.Render("~/scripts/jquery.validate.min.js")
@Scripts.Render("~/scripts/jquery.validate.unobtrusive.min.js")


When you click add, сlimbs another message in a different style.



enter image description here



This text contained in:



$('#txtMail')[0].validationMessage


How to me to achieve that when using Ajax of the request the same message?







c# jquery ajax asp.net-mvc validation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 at 6:45







Андрей

















asked Jan 3 at 16:05









АндрейАндрей

1135




1135













  • Can you provide model class (including data annotations), controller action and corresponding scripts related to client-side validation message? I tried to create this fiddle with your current setup but still not understand the problem.

    – Tetsuya Yamamoto
    Jan 4 at 2:41











  • @TetsuyaYamamoto I described in the question in more detail everything you asked for. If there are any other questions, write.

    – Андрей
    Jan 4 at 6:49



















  • Can you provide model class (including data annotations), controller action and corresponding scripts related to client-side validation message? I tried to create this fiddle with your current setup but still not understand the problem.

    – Tetsuya Yamamoto
    Jan 4 at 2:41











  • @TetsuyaYamamoto I described in the question in more detail everything you asked for. If there are any other questions, write.

    – Андрей
    Jan 4 at 6:49

















Can you provide model class (including data annotations), controller action and corresponding scripts related to client-side validation message? I tried to create this fiddle with your current setup but still not understand the problem.

– Tetsuya Yamamoto
Jan 4 at 2:41





Can you provide model class (including data annotations), controller action and corresponding scripts related to client-side validation message? I tried to create this fiddle with your current setup but still not understand the problem.

– Tetsuya Yamamoto
Jan 4 at 2:41













@TetsuyaYamamoto I described in the question in more detail everything you asked for. If there are any other questions, write.

– Андрей
Jan 4 at 6:49





@TetsuyaYamamoto I described in the question in more detail everything you asked for. If there are any other questions, write.

– Андрей
Jan 4 at 6:49












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025878%2fvalidation-of-the-form-with-ajax-request%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025878%2fvalidation-of-the-form-with-ajax-request%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas