ASP.NET MVC 4网站上的双重样式

时间:2021-10-09 21:08:57

I'm not sure if this is a common query but here goes...

我不确定这是否是一个常见的查询但是这里...

We are developing an ASP.NET MVC 4 website and a requirement has come up to be able to have two sets of styles running at the same time. The idea being that a select few people will get to the see a certain (new) set of styles and the rest will see the current styles.

我们正在开发一个ASP.NET MVC 4网站,并且要求能够同时运行两组样式。我们的想法是,少数几个人会看到一些(新的)样式,其余的将看到当前的样式。

Ideally, we do not want to have separate pages or a separate website to cater for this. What I'd like to know is what is the best way of going about this? Are there any common practices that should be followed?

理想情况下,我们不希望有单独的页面或单独的网站来满足这一需求。我想知道的是,最好的方法是什么?是否有任何应遵循的常规做法?

Thanks!

谢谢!

2 个解决方案

#1


1  

Just create another layout. They're not special: just partial views like any other partial view, with the exception that they use @RenderBody() to include the content from the current view being rendered.

只需创建另一个布局。它们不是特殊的:只是部分视图像任何其他部分视图一样,除了它们使用@RenderBody()来包含正在呈现的当前视图中的内容。

You can then either explicitly specify the layout in your view(s):

然后,您可以在视图中明确指定布局:

@{
    Layout = "~/Views/Shared/_AlternateLayout.cshtml";
}

Or you can add/edit a _ViewStart.cshtml file to the directory or directories containing views that should be rendered with the alternate layout. That file would just include the code above and nothing else.

或者,您可以将_ViewStart.cshtml文件添加/编辑到包含应使用备用布局呈现的视图的目录。该文件只包含上面的代码,没有别的。

Then you can customize it however you like.

然后你可以自己定制它。

#2


0  

The common way to do this is to have two separate CSS style sheets, and swap in one or the other based on whatever criteria determines which group the user is in.

执行此操作的常用方法是使用两个单独的CSS样式表,并根据确定用户所在组的任何条件在一个或另一个中进行交换。

This requires keeping all (or at least most) style declarations out of the markup -- no (minimal) use of the style attribute in your source HTML>

这需要将所有(或至少大多数)样式声明保留在标记之外 - 在源HTML中没有(最小)使用style属性>

#1


1  

Just create another layout. They're not special: just partial views like any other partial view, with the exception that they use @RenderBody() to include the content from the current view being rendered.

只需创建另一个布局。它们不是特殊的:只是部分视图像任何其他部分视图一样,除了它们使用@RenderBody()来包含正在呈现的当前视图中的内容。

You can then either explicitly specify the layout in your view(s):

然后,您可以在视图中明确指定布局:

@{
    Layout = "~/Views/Shared/_AlternateLayout.cshtml";
}

Or you can add/edit a _ViewStart.cshtml file to the directory or directories containing views that should be rendered with the alternate layout. That file would just include the code above and nothing else.

或者,您可以将_ViewStart.cshtml文件添加/编辑到包含应使用备用布局呈现的视图的目录。该文件只包含上面的代码,没有别的。

Then you can customize it however you like.

然后你可以自己定制它。

#2


0  

The common way to do this is to have two separate CSS style sheets, and swap in one or the other based on whatever criteria determines which group the user is in.

执行此操作的常用方法是使用两个单独的CSS样式表,并根据确定用户所在组的任何条件在一个或另一个中进行交换。

This requires keeping all (or at least most) style declarations out of the markup -- no (minimal) use of the style attribute in your source HTML>

这需要将所有(或至少大多数)样式声明保留在标记之外 - 在源HTML中没有(最小)使用style属性>