样式和脚本在部分视图中不起作用 [英] styles and scripts not working in partial view

查看:83
本文介绍了样式和脚本在部分视图中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个局部视图(asp.net-mvc),其中包含一些dropdownlist,其类别为选择-选择".但是以某种方式,该类没有得到应用. dropdownlist的显示/样式为正常".

I have a partial view (asp.net-mvc) that contains a few dropdownlist's with the class ''chosen-select'. But somehow that class doesn't get applied. The dropdownlist's are displayed/styled as 'normal'.

@using (var f = Html.Bootstrap().Begin(new Form("Home", "Index").FormMethod(FormMethod.Post).Type(FormType.Horizontal).InputWidthMd(12)))
{
    @f.FormGroup().DropDownListFor(model => model.Currency, Model.Currencies).Class("chosen-select")

    @f.FormGroup().ListBoxFor(model => model.CountryIds, Model.Countries).ShowValidationMessage(false).HtmlAttributes(new { @class = "chosen-select" })

    @f.FormGroup().ListBoxFor(model => model.USStateIds, Model.USStates).Id("usStates").ShowValidationMessage(false).HtmlAttributes(new { @class = "chosen-select" })

    @Html.Bootstrap().SubmitButton().Text(Resources.Form.Save).Class("btn btn-primary").HtmlAttributes(new { @style = "float:right;" })
}

partial view显示在对话框中.

$(document).ready(function () {
        $('.chosen-select').chosen();
});

不确定是否相关,但是jquery代码和样式放置在呈现此partial view的视图中.起初它和partial view在同一页上,但是jquery代码和css样式似乎没有任何作用.这就是为什么我重新安置它们(不确定是否也相关).

Not sure if it's relevant, but the jquery code and the styles are placed in the view that renders this partial view. It was on the same page as the partial view at first, but the jquery code and the css styles doesn't seem to do anything. That's why I relocated them (not sure if that's relevant either).

我正在通过AJAX调用渲染此partial view.

I'm rendering this partial view by the way, via an AJAX call.

推荐答案

也许问题在于您正在准备好对文档执行jQuery,然后呈现部分视图AJAX后缀,因此jQuery永远不会被应用.尝试执行此操作以初始化所选内容:

Perhaps the problem is that you are executing your jQuery on document ready and then rendering the partial view view AJAX afterwords, so the jQuery is never applied. Try doing this to initialize chosen:

$( document ).ajaxComplete(function() {
    $('.chosen-select').chosen();
});

这篇关于样式和脚本在部分视图中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆