admin管理员组文章数量:1391925
I have a strange problem where the unobtrusive validations inside a partial view (which is being rendered by a Ajax.ActionLink) does not work.
This is the Partial View:
@model MyWeb.Models.PersonSkill
@using (Ajax.BeginForm("EditSkill", null, new AjaxOptions { UpdateTargetId = "skills" }, new { id = "EditSkillForm" }))
{
@Html.HiddenFor(model => model.Id)
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.YearsOfExperience)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.YearsOfExperience)
@Html.ValidationMessageFor(model => model.YearsOfExperience)
</div>
<p>
<input type="submit" value="Save"/>
</p>
}
And this is called by:
@Ajax.ActionLink("Edit", "LoadEditSkill", new { id = item.Id }, new AjaxOptions() { UpdateTargetId = "editSkillDialog" }, new { @class = "editSkill" })
The view is rendered fine. It posts back data to the server, but it just doesn't validate.
I have a strange problem where the unobtrusive validations inside a partial view (which is being rendered by a Ajax.ActionLink) does not work.
This is the Partial View:
@model MyWeb.Models.PersonSkill
@using (Ajax.BeginForm("EditSkill", null, new AjaxOptions { UpdateTargetId = "skills" }, new { id = "EditSkillForm" }))
{
@Html.HiddenFor(model => model.Id)
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.YearsOfExperience)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.YearsOfExperience)
@Html.ValidationMessageFor(model => model.YearsOfExperience)
</div>
<p>
<input type="submit" value="Save"/>
</p>
}
And this is called by:
@Ajax.ActionLink("Edit", "LoadEditSkill", new { id = item.Id }, new AjaxOptions() { UpdateTargetId = "editSkillDialog" }, new { @class = "editSkill" })
The view is rendered fine. It posts back data to the server, but it just doesn't validate.
Share Improve this question edited May 1, 2013 at 3:05 RyanJMcGowan 1,5151 gold badge16 silver badges33 bronze badges asked Oct 8, 2012 at 15:47 ncabralncabral 2,5221 gold badge19 silver badges20 bronze badges 1- stackoverflow./questions/8927933/… – Joe Commented Oct 8, 2012 at 15:57
2 Answers
Reset to default 5Many thanks to Joe Tuskan for pointing me at the right direction.
I fixed the issue by adding an OnSuccess subscriber to my call:
@Ajax.ActionLink("Edit", "LoadEditSkill", new { id = item.Id }, new AjaxOptions() { UpdateTargetId = "editSkillDialog", OnSuccess = "onSuccess" }, new { @class = "editSkill" })
and adding calling parse() like explained here:
var onSuccess = function () {
// enable unobtrusive validation for the contents
// that was injected into the <div id="result"></div> node
$.validator.unobtrusive.parse($("#editSkillDialog"));
};
Always make sure you included the necessary references to
jquery.validate.min.js and jquery.validate.unobtrusive.min.js and of course the main jquery library, this is usually the most mon problem, and as i can see in your cshtml they are not present in your page either.
本文标签: cMVC3 Ajax Form Validation with Partial View not WorkingStack Overflow
版权声明:本文标题:c# - MVC3 Ajax Form Validation with Partial View not Working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744663551a2618394.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论