I need to use a css template for webpage I am building but I don't know how to use in asp.net mvc4. so How to use CSS Templates with ASP.NET MVC 4 in visual studio 2012 for web application?
3 Answers
It's simple:
Move your css and images into
~/Contentsfolder.Move your js files into
~/ScriptsfolderCopy and paste your
htmlsnippets tocshtmlfilesOn 3rd step you need to port the layout portion of your template to
~/Veiws/Shared/_Layout.cshtml. Here you need to point references to your css and js correctly. For example:And also you need to be aware that
_Layout.cshtmlshould contain@RenderBody(). That's where all child views will be inserted.
Just found a video with basic demonstration of process: link
Comments
It is the same as you use for simpe HTML files. In the solution you can add an existing item and your browse your CSS file which will be added in the Content folder then you have to reference it in the page where it will be used.
If you want to apply all the rules to every page you can reference it in the _Layout.cshtml page which is called before everypage. It is like the container.
You have many options to call it. I will suggest you also reading Bundling and minification in this link which is also interesting to know.
Comments
There are Few Steps:
- Make Directory inside Content folder in my case mytemplate.
- Copy all your template content inside mytemplate folder.
- Add new Layout page in View>Shared Folder in my case _mytemplate.cshtml.
- open your template Index.html file inside any editor(i.e: Dreamviewer,Notepad etc).
- Copy all header stuff from your html file to inside of Header in _mytemplate.cshtml file.
- Copy all body stuff Inside of your Index.cshtml to Layout page.
- Save your Project by Cntrl+S and Run it in browser. Thats it.