gpt4 book ai didi

c# - 部分 View 不工作的 MVC3 Ajax 表单验证

转载 作者:太空狗 更新时间:2023-10-30 00:54:27 26 4
gpt4 key购买 nike

我有一个奇怪的问题,部分 View (由 Ajax.ActionLink 呈现)内的不显眼的验证不起作用。

这是局部 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>
}

这是调用者:

@Ajax.ActionLink("Edit", "LoadEditSkill", new { id = item.Id }, new AjaxOptions() { UpdateTargetId = "editSkillDialog" }, new { @class = "editSkill" })

View 渲染良好。它将数据回发到服务器,但它只是不验证。

最佳答案

非常感谢 Joe Tuskan 为我指明了正确的方向。

我通过在调用中添加 OnSuccess 订阅者解决了这个问题:

@Ajax.ActionLink("Edit", "LoadEditSkill", new { id = item.Id }, new AjaxOptions() { UpdateTargetId = "editSkillDialog", OnSuccess = "onSuccess" }, new { @class = "editSkill" })

并像解释的那样添加调用 parse() here :

var onSuccess = function () {
// enable unobtrusive validation for the contents
// that was injected into the <div id="result"></div> node
$.validator.unobtrusive.parse($("#editSkillDialog"));
};

关于c# - 部分 View 不工作的 MVC3 Ajax 表单验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12785086/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com