I have a MVC 3 web application for which I would like to implement a theme/templating framework (similar to Wordpress or Joomla where you can enable or disable different themes for a site) and would like to find out what is the best way to accomplish this.
My design constraints are this. I buy HTML templates from places like Themeforest or Template Monster and want to make a number of these templates available for use in my web app. The templates you typically buy online all have very different CSS layout frameworks, so it's not possible to just drop a new CSS in your /Content/Themes/ folder and then your views work with this because you also have to make changes to the HTML in the Views. So for every new theme in /Content/Themes I also need a new set of /Views/ folders where the HTML is updated to use the proper CSS classes for that theme.
I know in an ideal world I should just have all the CSS compatible with my html views (ie theme switching is purely based on loading a new CSS), but in this case that is just not possible.
So I'm wondering if there is way to tell MVC where the current default Views folder is? A possible project structure I'm thinking of is something like this:
/Themes/Theme1/Views/(all cshtml view pages for this theme goes here)
/Themes/Theme2/Views/(etc)
I know that I can force the views like this
return View("~/Themes/Theme1/Views/Controller/Index.cshtml")
which can be extended to dynamically determine the theme folder with something like this
return View(currentThemeFolder + "/Views/Controller/Index.cshtml")
but I am wondering if there is a better way to do this? Is there someway perhaps in the global.asax to set the default "Views" folder so that the above is not necessary? There must be an entry point to the views because how do you then specify which _viewstart.cshtml file is called? And if I do go for the above design of forcing/"semi-hard-coding" the views what are the down sides to it?
I also want to say that I have not looked much at Areas in MVC 3 and I don't think that would work here, because my understanding is that it would affect your routing, and would also duplicate your model and controllers folders which I don't want. I have on central Model and Controllers folders, but just need multiple Views folders.
You can extend VirtualPathProviderViewEngine to create your own themeable view engine. Here is how: http://www.singingeels.com/Articles/Creating_a_Custom_View_Engine_in_ASPNET_MVC.aspx
Related
I need to implement a Telerik control into an existing page of a MVC5 project.
The problem is that I don't own the source code of the project (it's an off the shelf framework) so when I open it in VS there is not the model and controller files (only the shared view) so I cannot modify it accordingly to my needs. The shared view is a cshtml file with pure HTML stuffed with a bunch of HTML helpers and a couple Razor blocks.
Since I am pretty new in MVC I would like to know if it's possible that I create a custom "partial view" from scratch inside this project and invoke it from the shared view.
I am asking the feasibility of it before I waste a lot of time chasing my own tail on something that cannot be done... :/
I am working on a dating site. The website will have multiple front end themes. I want to follow good practice when setting up the structure of the project. I have posted an image of how the structure will look like. Multiple front end themes in the themes folder containing all the images, css, etc related to that theme in the folder.
Am I on the right track here? How can I tell Spring which theme I want loaded?
Use Sitemesh to change theme depends on your URL pattern
http://codesilo.wordpress.com/2013/07/11/spring-mvc-with-sitemesh-3/
Is there a Design View in ASP.NET MVC3 ?
There is no 'Design' view in MVC, like there is in Forms. However your views are just HTML so you can use any HTML editor, although they will not be able to interpret the Razor syntax.
What most people do is make changes to the HTML, save (you don't have to recompile,) and refresh your browser. Google Chrome has a very help full tool built in (Firebug or something like it.) Just right click on the page and select Inspect Element. This will come in very handy.
Also one thing to think about since you're new to MVC is that you can easily use most any css themes that you can find online to make the site look very different out of the box.
I would like to create a PhoneApplicationPage dynamically and navigate to that page. Is this possible?
Edit: I am developing a number of applications which will share a couple of pages. I want to avoid code duplication and create them in code once and share them across these applications.
I certainly do not want to bypass the built in page navigation by using custom content or any other means. I was hoping that I could programatically create the pages, register or inject them into the navigation system and use them the same way as if they were created at design time.
The navigation system supports loading pages created in libraries (in fact, it's often used to improve startup speeds by moving large, uncommonly used pages out of the main assembly).
Assuming you have created a Windows Phone Library project named CommonPages that incldes a page Common.xaml, you can navigate to it using the URI /CommonPages;component/Common.xaml
Remember to add a reference to your library from your main project.
I would like to make custom editor templates for different data types in ASP.NET MVC (to use with Html.EditorFor()), including rewriting the existing templates. The ultimate goal is to create a mini-framework where each editor supports javascript notifications about being changed, and I can show a message to the user that there are unsaved changes in the page. (Maybe there's something existing already?)
I can find many questions pertaining to problems with such templates, but nowhere can I find a tutorial or manual on creating them. Where do they go? Is there any special syntax? How does a template get selected? What information is available in the template and how do I access it? Etc.
So - where can I find out all about these templates?
Check and download ASP.NET MVC 3 Futures on http://aspnet.codeplex.com/releases/view/58781 and see how the default source code looks. Note: this works for MVC 4 as well.