【问题标题】:DevExpress get stylesheet add variableDevExpress 获取样式表添加变量
【发布时间】:2017-09-15 15:05:38
【问题描述】:

我在一个使用 javascript 的 ASP.net MVC 应用程序中工作。我正在使用 devExpress dxSwitch 尝试更改页面的主题。

我的 _layout.cshtml 中有这段代码

    @Html.DevExpress().GetStyleSheets( "dark",
    new StyleSheet { ExtensionSuite = ExtensionSuite.NavigationAndLayout },
    new StyleSheet { ExtensionSuite = ExtensionSuite.Editors },
    new StyleSheet { ExtensionSuite = ExtensionSuite.GridView },
    new StyleSheet { ExtensionSuite = ExtensionSuite.Dashboard}
)

我不想在主题中硬编码“暗”,而是想看看是否可以使用变量代替它并应用此函数在明暗之间切换。

$('#switch').click(function () {


            var whichTheme = $("#switch").dxSwitch("instance");
            var valueSwitch = whichTheme.option("value");
            if (valueSwitch === true) {

                $('body').css('background-color', '#343434');

            } else {

                $('body').css('background-color', 'whitesmoke');
            }
        });

【问题讨论】:

    标签: javascript asp.net-mvc razor devexpress devextreme


    【解决方案1】:

    我认为你没有机会这样做。 Javascript 和 Razor 不通信,因为渲染发生在 jQuery 开始工作之前。

    我会查看 DevExpress 输出的 HTML,然后在元素本身或页面上的样式标记中添加或更改样式。

    【讨论】:

      【解决方案2】:

      看来你想要的是https://codecentral.devexpress.com/E3825/Home/PostTheme这样的东西,你可以这样做,但它并不像你想象的那么简单,请检查这个示例代码

      namespace MvcApp_Theme {
          // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
          // visit http://go.microsoft.com/?LinkId=9394801
      
          public class MvcApplication : System.Web.HttpApplication {
              public static void RegisterGlobalFilters(GlobalFilterCollection filters) {
                  filters.Add(new HandleErrorAttribute());
              }
      
              public static void RegisterRoutes(RouteCollection routes) {
                  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
                  routes.IgnoreRoute("{resource}.ashx/{*pathInfo}");
      
                  routes.MapRoute(
                      "Default", // Route name
                      "{controller}/{action}/{id}", // URL with parameters
                      new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
                  );
      
              }
      
              protected void Application_Start() {
                  AreaRegistration.RegisterAllAreas();
      
                  RegisterGlobalFilters(GlobalFilters.Filters);
                  RegisterRoutes(RouteTable.Routes);
              }
      
              protected void Application_PreRequestHandlerExecute(object sender, EventArgs e) {
                  DevExpressHelper.Theme = Utils.CurrentTheme;
              }
          }
      }
      

      你有完整的代码在这个链接https://www.devexpress.com/Support/Center/Example/Details/E3825/how-to-change-a-theme-on-the-fly

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-20
        • 2022-10-14
        • 2020-09-10
        相关资源
        最近更新 更多