Unobtrusive validation not working on jquery tabs using partial view

房东的猫 提交于 2019-12-25 12:51:26

问题


I'm using jquery-ui tabs to display partial views. I have a view that contains the tabs definition:

<ul>
    <li><a href="@Url.Action("CreateTab","Catalogue")">Create</a></li>
    ...

And a controller method CreateTab which returns a PartialView:

public ActionResult CreateTab()
{
    var model = new StockCatalogueItemViewModel
    {
    ... populate some selectlists
    }
    return PartialView(model);

The model property that I'm validating has datatannotations on and I can see that the validation tags have been rendered in the HTML.

However the client-side validation simply isn't firing. The server-side validation is working fine and is correctly showing the invalid fields.

There is nothing wrong with the script bundles as validation works perfectly on other pages (albeit not using partial views), so I can only think it's something to do with the fact that I am using partial views. I've seen other posts related to this issue but none seem to help. Note that I'm NOT loading the partial views using ajax. I'm not doing anything complicated here, so why isn't it working?


回答1:


Since you're not using Ajax.BeginForm(), I'm pretty sure you need to use $.validator.unobtrusive.parse("#ID); in your javascrpt to specify that there's new validator information you want applied.



来源:https://stackoverflow.com/questions/23998964/unobtrusive-validation-not-working-on-jquery-tabs-using-partial-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!