How create dynamic view page and css file in mvc3 - c#

I am working on small project Fast Food Ads in Mvc3 using c# .I want to create page where user can set the layout of page like header , footer and menu bar etc. manually so I think this page its HTML and Css file should be create dynamically. page name and css file will be unique for every user how can i do this?
I don't want to use any CMS...

In principal you can use the Razor engine in MVC3 to process any of your files. You can already do that for your HTML files.
If you want to use Razor to dynamically process (or even create, on the fly) your CSS, have a look at RazorJs. RazorJs allows Razor to pre-process Javascript files before they are included in a view. I have not looked at it's source code, but I imagine it should be straightforward to adapt it to pre-process CSS as well.

Related

Design Issue - Creating aspx pages dynamically

I currently have a web application that serves a single dashboard page. The client would like multiple dashboards for different systems displayed on the same physical machine. They would like to avoid installing many instances of the application as this would require opening up too many ports to view different dashboards.
They have suggested I alter my application to include multiple tabs/pages for each dashboard. Currently I have some C# classes which gather and process the data and feed it into the Default.aspx.cs file which then uses Web HTML controls to generate the html content and feed it into Default.aspx page via a placeholder.
At runtime I don't know how many Dashboards there will be or what they will be called (the C# classes read information from textfiles located in each dashboard directory on the drive, C:\Dashboard1*.txt C:\Dashboard2*.txt).
I am new to this and I'm struggling to see how to split the design out so that I can dynamically create the aspx.cs file and aspx file for each dashboard object.
Would a solution be to create a Dashboard.cs class that handles all the html generation (in place of default.aspx.cs) and creates an aspx page dynamically for each dashboard found on C:. Would all of the Web HTMLControls still work without a link between an aspx.cs file and a aspx file?
I realise this question is vague...more specifically I guess I am asking:
How do I create an aspx page dynamically from a C# class and then add web html controls to it? E.g. create the aspx page from a template and then use controls like HTMLGenericControl RowDiv = new HTMLGenericControl('div'). I wouldn't know how to link my C# class to the newly created aspx page so that the HTML Web controls knew they were supposed to be added to that new aspx page.
I would create the dashboard as an user control, and add the controls you need dynamically. Doing it like this you also have the option to create different looking dashboards (if you need it).

How to Integrate Bootstrap Template with MVC

I have downloaded a Bootstrap template(Complete GUI) from the internet and I want to add functionality to the same template using MVC. So how should I add that template to my MVC project.
I have seen many tutorials but they only tell you how to add a theme not an entire template.
I am using the cardio theme: http://tympanus.net/Freebies/Cardio/
The default MVC project includes a _Layout.cshtml file, which contains the main HTML for your template. Replace that with the HTML in the template you downloaded, making sure to copy the bits of Razor from the old code.
Then you'll need to replace the CSS files with the ones from the downloaded template and it should all work.
This all depends on how well written the template is, but I've done this many times with no problem.

Loading html page from a template on the computer

I am working with a C# on visual studios.
What I would like to know is if it is possible to have a html template loaded from a directory on my computer. Then every time I load up my code it will load up the .html template automatically.
Yes there is a way, not suggested but exist. You can use this code to include the file, inside your asp.net page.
<!--#include file="template.htm"-->
What is dose is that is load this htm file and show it on the place that you have place this declaration. Also you must know that this file can not contain anything dynamically. This is a command code that comes from the old asp script code, and still work on asp.net
So I can not call it as template. If you wish to make something like a real template you must use a master page. Using a master page is far better, and you just copy paste your htm code inside the master page and there you have it.
relative: http://triaslama.wordpress.com/2008/11/19/how-to-include-file-in-aspnet-pages/

Ajax Template Editor for Reports

I have been tasked to create a layout editor for my companies internal Reporting System. The Specifications they gave me indicate that templates must be able to be defined in .html files in a certain folder. These HTML files can have their own style etc. So it's a full HTML page with the html, head and body tag with content areas that are indicated with special a syntax.
Now what's been bothering me is that I have to load this page with it's styling etc. into a layout div (or IFrame maybe?) where I need to be able to work on it with Javascript (Using JQuery) to insert the controls to manage how the data is displayed.
I can't seem to find a way to do this. Any ideas as to how achieve this according to specifications? Any Help will be appreciated.
The only way to load the page with all referenced stylesheets applied appropriately, and avoiding javascript conflicts is to embed the html in an iframe.
This does however mean that your page will have to be served from the same domain as your application in order for you to be able to interact with the content in an easy way, but as long as this is so (possibly using your app as a proxy for the pages) there is cross browser support out there from jQuery * other javascript frameworks are available I'm sure.

Move baseclasses for MasterPage from MVC2 to MVC3

I am working on moving an application from MVC2 ASPX to MVC3 Razor, and is quite stuck moving a baseclass for more MasterPages in old MVC2 application.
The baseclass is used for automate include of css and js on pages in order to ease quickfix and debugging when developing application in local environment, but when running application in production environment it has to update and include single minimized css and js files delivered from a external CDN.
The code needs to know about the View file eg. "~/views/home/index.chtml" and/or the Layout file eg. "~/Views/DefaultNoLogon.Master" in order to include and handle css and js files correct.
I tried to implement own baseclass using the pageBaseType in Razor part of web.config, but it seems like it is executed both for View and Layout file, and I could not find a execution point where information about both View and Layout file is present. I also tried to implement the file logic using a HtmlHelper, but I can only access information about the View file and miss information for Layout file for View.
I don't want this kind of code to be implemented in Route, Controller or ViewModel since it should be related directly to generation of Views.
Any ideas how to get information about View and Layout files in MVC3 Razor app?
Well, never mind my question.
I redesigned my logic for automatic rendering of js and css files, which actually is more simple and works better. My Mvc3 Razor app is now capable to take all js and css files for a view (including css and js for all layoutpages) and render them into single minified files.
Works like a charm, and I guess it's more future proof than my old solution, unless Guthrie make fundamental changes in layoutpages and Html helpers in Mvc4 or later.

Categories

Resources