如何仅在验证后执行 ASP.Net MVC Ajax.ActionLink?
Net MVC 3.0项目
我的页面中有一个表单和一个Ajax.ActionLink,它向当前表单添加另一组字段,这是一个重复的过程,只要用户不断单击ActionLink,它就会不断添加越来越多的字段表单的字段集。
这是我的 Ajax 操作链接,
@Ajax.ActionLink("Add Another ERx", "ERxView", "Medication", new AjaxOptions
{
UpdateTargetId = "accordion",
InsertionMode = InsertionMode.InsertAfter,
HttpMethod = "POST",
OnBegin = "destroyAccordion",
OnSuccess = "createAccordion"
}, new { @class = "standard button", id = "AnotherErx", onclick = "document.ERxForm.submit();"})
我的问题是
当用户单击该链接时,它应该首先验证当前表单中的所有必填字段,只有成功验证后,它才应该将新的字段集附加到表单中。
我在 Ajax.ActionLink 中尝试了类似的操作,在单击 ActionLink 时验证当前表单,
onclick = "document.ERxForm.submit();"
这会触发表单验证,但无论验证如何,它都会继续向表单添加新的字段集。
任何人都可以帮助我,我怎样才能实现这一目标
感谢所有花时间阅读我的问题的人。
Net MVC 3.0 Project
I have a form in my page and a Ajax.ActionLink which adds another set of Fields to the current form, and this is a repetitive process, as long as user keeps clicking the ActionLink, it will keep adding more and more set of Fields to the form.
Here is my Ajax Action Link
@Ajax.ActionLink("Add Another ERx", "ERxView", "Medication", new AjaxOptions
{
UpdateTargetId = "accordion",
InsertionMode = InsertionMode.InsertAfter,
HttpMethod = "POST",
OnBegin = "destroyAccordion",
OnSuccess = "createAccordion"
}, new { @class = "standard button", id = "AnotherErx", onclick = "document.ERxForm.submit();"})
My Problem is
When user clicks on the link it should first validate the current form for all required fields, upon successful validation only it should append the new set of Fields to the form.
I tried something like this in my Ajax.ActionLink to validate current form upon clicking the ActionLink
onclick = "document.ERxForm.submit();"
this fires an Form Validation, But irrespective of Validation, it continues adding the new set of fields to the form.
Can any one help me, How can I achieve this
Thank for all who is taking time to read my question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最有可能的问题是您正在添加要验证的新元素。如果您通过 AJAX 添加新的验证元素,则需要清除并重新解析页面上的所有验证属性,如下所示:
将其添加到您的
OnSuccess
函数中,验证将对所有元素起作用在页面上,原始的和添加的。The issue most likely is that you are adding new elements to be validated. If you add new validation elements via AJAX, it is necessary to clear and re-parse all validation attributes on the page, like so:
Add this to your
OnSuccess
function, and the validation will work for all elements on the page, original and added.让 destroyAccordion 函数调用验证函数并返回 true 或 fals。
如果为真,则执行操作链接。
Make destroyAccordion function call validation function and return true or fals.
If it is true then Action link executes.