如何将样式应用于视图 [英] How to apply styles to views

查看:95
本文介绍了如何将样式应用于视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有2个文件夹第1个是共享文件夹,其中有Layouts,第2个文件夹是home文件夹,因为我添加了常用链接



最后我想利用css类到index.cshtml视图,该视图位于已经具有layout.cshtml页面功能的Home文件夹中(位于Shared文件夹中)。如何将样式应用于index.cshtml(位于Home文件夹中)



请帮助我,我是MVC3的新手

I have 2 folders in my project 1st one is "shared" folder that has Layouts and 2nd folder is "home" folder in that i had added common links

finally i want to utilize css classes to index.cshtml view which is in Home folder that already having "layout.cshtml" page features(which is in Shared folder). how can i apply styles to index.cshtml(which is in Home folder)

Kindly please help me i am new in MVC3

推荐答案

那么,你有没有读过任何MVC教程?我想不是。不如从这里开始: http:/ /www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/intro-to-aspnet-mvc-3 [ ^ ]



只是回答你的问题:

1)首先,忘记ASP.NET Web表单,并尝试仅考虑html和css。 />
2)共享文件夹包含(以及其他)您的布局。从动作调用的视图通常存储在像控制器一样的文件夹中(这是一个惯例,而不是规则)

3)你会看到,布局文件和实际视图是合并的,如果为视图指定布局

4)模板将layout.cshtml设置为所有视图的默认布局,因此视图本身将在布局内呈现。

5)因此你在布局中放置的样式表也将应用于视图(site.css)

6)但是:这不是皮肤,它是标准的css样式表。因此,您可以根据需要在视图中生成的元素上使用适当的类和/或更改样式表。
Well, have you read any MVC tutorial out there? I suppose not. Well than start here: http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/intro-to-aspnet-mvc-3[^]

Just to answer to your question:
1) First, forget ASP.NET Web forms, and try to think in html and css only.
2) "Shared" folder contains (among others) your layout(s). The views called from actions are usually stored in folders called just like the controller (this is a convention, not a rule)
3) You will see, that the layout file and the actual view are merged, if you specify a layout to the view
4) The template has layout.cshtml set as default layout for all views thus the view itself will be rendered inside the layout.
5) Thus the stylesheet you have put in the layout will be applied to the view also (site.css)
6) But: this is no "skin", it is standard css stylesheet. Thus it is up to you to use the proper classes on the elements generated in the view and/or alter the stylesheet according to your needs.


这篇关于如何将样式应用于视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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