Let graphic designer edit views in ASP.NET MVC - asp.net-mvc

We have graphic/interface designer who is developing html/css for our websites.
How can I let him work on cshtml and css files without giving him access to controllers and models?
Greetings

Why not separate the Controller and Models into separate Class Library projects, referenced by the MVC project? That way, you can expose the MVC project, including the views, styles and scripts, but keep the infrastructure private.
So long as you keep the naming convention correct, you shouldn't have any issue with controllers being separate.

Related

Areas vs Folders in MVC

I am not to relate to Areas in MVC, why cannot we have simple folders to indicate modules, is the web.config which needs to be there, the below is the reason why i am asking this
Views -unfortunately for views it’s not possible. All the views must be placed inside “~/Views/ControllerName” or “~/Views/Shared” folder.
The following article describes in detail the reasons for Areas and the difference between Areas and folder-based conventions in ASP.NET MVC.
http://www.codeguru.com/csharp/.net/net_asp/mvc/article.php/c20227/Using-Areas-in-ASPNET-MVC-Application.htm
The essential idea is contained in the Introduction of the article:
ASP.NET MVC relies on certain folder and class naming conventions to
organize models, views and controllers. A large application often
consists of functionally independent modules with the result that the
main application is essentially a bundle of these sub-applications. In
such cases, organizing various models, views and controllers can be
tedious. Luckily, ASP.NET MVC allows you to split your application
into what is known as Areas. Each area mimics the folder structure and
conventions as required by ASP.NET MVC. This article shows you how
Areas are used in an ASP.NET MVC application.
When someone is trying to develop a sub-module suitable for inclusion in any ASP.NET MVC application (as an example, think deployment/inclusion of 3rd party code via a NUGET package) then the Areas construct is very helpful, and arguably a necessity.
Areas are folder structure which contains its independent set of Controller,
View, Model. Consider we are creating an area called Admin then the folder structure for the Admin area will be,
The same setup can be created by adding folders, Subfolder, and Required files.

Asp.net MVC 5 separate projects for UI and Web

How can I go about separating my MVC project into UI specific (JS, CSS, Images, Fonts, and maybe Views) and Controller/Model specific (Controllers, Helpers, Models, and may be Views). Since our front-end developers work mostly independent of Visual Studio, I was looking for best practices in separating projects. Any pointers or sample projects?
This is how we finally ended up doing it.
Create a separate visual studio project called SolutionName.Client (this is where all frontend js and scss files go)
Create you MVC project called SolutionName.MVC (this is the asp.net mvc project)
Using Grunt.JS write tasks that compiles all js and css files and drops them to SoltuionName.MVC/Content folder
Similarly write tasks that drops all Views (razor files) into SolutionName.MVC/Views folder.
In Project build settings, add a pre-build tasks to run grunt task.
This setup took few hours to get it working but it is now quite useful.
You can easily do this and I've done it for each of my projects in MVC as well.
One project has your Controllers, ViewModels, and in my case, any custom logic related to Dependency Resolution for MVC and custom classes related to security authentication with MVC. Basically any code that touches the MVC framework core and is not involved in rendering content.
The other one has pretty much everything that you use on the client-side, and code needed for the front end. Which in my case, code-wise, is very minimalist and included some code for Glimpse and Elmah. The rest is your Views, Styles, Scripts, static content like downloads, etc.
As for the files in App_Start, My views project has Bundles, Filters, and obviously any HtmlHelpers you may have, custom css transformationslike for LESS.
My Controller's App_Start has the RouteConfig. These aren't necessarily critical it's just the way I ended up organizing mine and really depends what aspects you need access to during the startup of those components.
I will say that to save yourself time, in your Views/web.config file, add a namespace entry for your Company.Project.ViewModels namespace so that it's done in one place and you don't have to add it to each view, as this namespace would reside in your Controllers Project.
Your project with the Views will be your startup project. Just make sure in the global.asax your calls to the FilterConfig, RouteConfig and BundleConfig all resolve correctly.
It's fairly easy to do, my recommendation is to try it yourself and split it out the way you want and if you have problems come back and ask about the difficulties rather than looking for a step by step guide.
Bottom line is, yes it's possible and yes it works,

Advantage of create ASP.NET MVC project with WebForm core reference

The 'New ASP.NET Project' dialog lets you create an MVC Project, and allows you to add a 'core reference' to Web Forms.
What is the advantage and usage of adding the WebForms reference?
Is it so the web project can contain both MVC views and controllers as well as WebForms pages?
Is it so the web project can contain both MVC views and controllers as well as WebForms pages?
Indeed. And if you check Web API, you can even create ApiController-derived controllers.
Sometimes you want to use multiple techniques in a single project. If you don't need it: don't check it. You can always add it manually when required later.

Re-Using complete Parent MVC project code but with different style

The Scenario :
I have my main base MVC project, with the model + view + controller that I want to re-use in my children MVC projects. But the children MVC projects's CSS styles are all different, and uses different localization resource files.
The question:
Is it possible to create such an MVC child project that references the parent MVC project, but uses different styles etc? The only difference between the projects are the styles and localization.
Or will I have to keep the views separate in each child project? (this feels like a waste because all the projects views will have the same code)
I am using TFS, so I don't think "File Linking" is an option
Regards
David
I see two ways:
Calculate main css file based on domain name (or other projects differences) and use it in view where css include to HTML
Create two views packs and switch it in projects (in addion you can change HTML in projects)
For example first way you may look http://www.getpets.me/ and http://www.getalljobs.com/ sites. They use one instance of code, but include different css files.
I only tested this briefly, but it seems to do the trick :
MvcApplicationRazorGeneratorSeparateLibrary.
There is a zip file you can download and test
This means you have two MVC projects, the main one creates all the views etc and compiles it.
Then you can reference it from the second MVC project, and only change the styling, content, web.config or add views in the second MVC project.

How can I make ASP.NET MVC 3 use views (aspx, ascx) files from an external assembly in my website?

I have an ASP.NET MVC 3 website and I'm looking for a way to package up a set of views and controllers into an external DLL and hopefully use MEF (Dependency Injection) to load the correct controllers and views.
Does anyone know if something like this is possible and any good links to tutorials on the subject?
Precompiled Razor for Shared Views and Mono
Compile your asp.net mvc Razor views into a seperate dll
A combination of those two will probably get the best result in your case - My precompilation code handles some things the single file generator doesn't, but Chris has more use of out of box code at runtime, which is probably better if you only need to run in a standard mvc3 setup.
I have also used aspx files set up as embedded resources ( Views in separate assemblies in ASP.NET MVC ), but Razor is quite a bit easier to work with in compiled form.

Resources