asp.net-mvc Asp.Net MVC 主题,如何?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/769878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-07 23:30:16  来源:igfitidea点击:

Asp.Net MVC Themes, how to?

asp.net-mvcthemes

提问by Jhonny D. Cano -Leftware-

I have a ASP.Net 2.0 site and want to translate it into MVC paradigm (I'm new to this), but starting from Zero.

我有一个 ASP.Net 2.0 站点,想将它转换成 MVC 范式(我是新手),但从零开始。

I have some themes in my old site, but reading here and there, it seems like Themes doesn't fit well into MVC paradigm.

我的旧站点中有一些主题,但在这里和那里阅读,似乎主题不太适合 MVC 范式。

The question is:

问题是:

What is the best practice in MVC for building a Themed user customizable site? Can you give a little example, if applicable?

MVC 中构建主题用户可自定义站点的最佳实践是什么?如果适用,你能举一个小例子吗?

Note: I'm aware of thisbut they don't talk about best practices or how to start with.

注意:我知道这一点,但他们没有谈论最佳实践或如何开始。

采纳答案by Chris Pietschmann

Here's my code that I've been using for implementing "Themes" in ASP.NET MVC:

这是我用于在 ASP.NET MVC 中实现“主题”的代码:

ASP.NET MVC: Implement Theme Folders using a Custom ViewEngine

ASP.NET MVC:使用自定义 ViewEngine 实现主题文件夹

It's nice when you're able to just swap out CSS files to change the theme, but this really isn't very practical in a ton of cases. Especially when each theme needs to have a completely different layout. In which case, you need to change the CSS and HTML that gets rendered, and this is why I wrote the code found at the above link.

当您能够仅交换 CSS 文件来更改主题时,这很好,但这在很多情况下确实不太实用。特别是当每个主题都需要完全不同的布局时。在这种情况下,您需要更改呈现的 CSS 和 HTML,这就是我编写在上述链接中找到的代码的原因。

回答by Mauricio Scheffer

A clean, semantically correct HTML with a good CSS is the way to theme any web app, whether it's ASP.NET, RoR, PHP, etc.

干净、语义正确的 HTML 和良好的 CSS 是为任何 Web 应用程序设置主题的方式,无论是 ASP.NET、RoR、PHP 等。

The best example of the power of CSS is CSS Zen Garden.

CSS 力量的最好例子是CSS Zen Garden

w3schools has a nice introduction/tutorial to CSS.

w3schools 有一个很好的CSS 介绍/教程

Each of your users could have an associated stylesheet which would get selected whenever applicable, i.e.:

您的每个用户都可以拥有一个关联的样式表,该样式表将在适用时被选中,即:

<link rel="stylesheet" type="text/css" href="<%= Model.SelectedStyleSheet %>"/>

回答by Joe Swan

As themes were intended to style up tags you can use CSS to create a similar approach. I would probably recommend that you start with copying your default themes over to css definitions e.g.

由于主题旨在设置标签的样式,您可以使用 CSS 来创建类似的方法。我可能会建议您首先将默认主题复制到 css 定义,例如

html: <input type="button" />

html: <input type="button" />

css: input { color : light-blue }

CSS:输入{颜色:浅蓝色}

Then for anything that had your non-default theme you can just apply classes to them. It takes a while to re-write all your themes as CSS, but once done it's worth the effort.

然后对于任何具有非默认主题的内容,您只需将类应用于它们即可。将所有主题重新编写为 CSS 需要一段时间,但一旦完成就值得付出努力。

回答by Morph

jQuery-uithemes are nice, and not too hard to implement.

jQuery-ui主题很好,而且不难实现。

Just link to the js and css file and don't forget the icons. And make sure to use Url.Content() in those links. Otherwise it might not be linked to the correct path, once you deploy it on a production server (i fell into that trap once).

只需链接到 js 和 css 文件,不要忘记图标。并确保在这些链接中使用 Url.Content()。否则,一旦您将其部署在生产服务器上(我曾陷入该陷阱),它可能无法链接到正确的路径。