How to organize MVC3 project in custom folders - c#

I’m starting to learn MVC3 and I’d like to know if it is advisable to group your views and controllers in folders different to the default ones.
So I could organize the project such as:
-->ClientsFolder
-Views
----ClientsAdmin(Folder)
------View1
------View2
------View3
----ClientInvoices(Folder)
------View1
------View2
------View3
-Controllers
----ClientsAdminController(File)
----ClientsInvoiceController(File)
-->EmployeesFolder
Etc..
Etc..
I’d like to know, if it is a common practise, how should I start to adapt the project to this structure or if somebody could point me to a tutorial which could help me started.
Thanks

What you are describing is a feature MVC 3 already has (since MVC 2 I think). Areas.
Walkthrough: Organizing an Application using Areas
UPDATE: New working link.

What you are doing is fine. There's no need for a new area for every controller, areas should be for large chunks of application that aren't really the main application (like an administration site for your main site).
This is an OK tutorial to get started MVC Movie Tutorial

ASP.NET MVC has a facility to partition Web applications into smaller units with areas.
For example you can create an admin area for the administration section.

There are Areas for arrange mvc project.
Don't invent the wheel again... =)

Related

Modularised ASP.NET MVC web site

I'm currently refactoring a huge ASP.NET MVC website. The main idea of what I'm trying to achieve is having a main (front) website and several separate websites in the same solution that can be deployed separately. The reason for that is that we have different teams working on a different project.
The current setup looks like this:
Main website ASP.NET MVC
Module 1 (Area)
Module 2 (Area)
other modules..
Common Business Layer
Common Data Layer
Common View Layer
When making changes to a module, you have to deploy the main website (so although Areas are acting as separate projects, they cannot be deployed separately). Areas are using RazorGenerator for the views. The Common View Layer generates Embedded Resources to be used in the main website/modules.
Any solution for that?
What I'm trying to accomplish right now is extracting the modules from Areas into full ASP.NET MVC websites and map them in IIS as subdomains to the main website. The problem here is that I have repeating views, styles, layouts in all projects and making a change to the main menu, style, etc. would mean going through all the projects and make that same change. Not a viable option.
Thanks for the ideas!
So the answer can depend also whether you want to have several solutions (*.sln) or it will be just one solution with several mvc projects.
Ad.1 Multiple sln / directories.
In that case probably interesting option is to configure virtual directory with some static content like styles, scripts etc. Such virtual directory can be quite easily configured on IIS: https://msdn.microsoft.com/en-us/library/bb763173.aspx
Ad.2 One solution, multiple MVC projects:
Then I'd suggest to add some solution folder like 'Common Presentation Layer Files' -> then I'd move all those files to be shared into that solution folder. Next in those MVC projects I would do following thing => right click => add existing item => as a link.
As the result you'll have a copies / shortcuts to the original files. You should do the updates only in that common folder and the changes will be visible in all other mvc projects. https://msdn.microsoft.com/pl-pl/library/9f4t9t92(v=vs.90).aspx Then you can publish your MVC projects separately and if properties of those static files are ok all the files will be copied during publish. So the structure would look like:
Solution:
MVC App 1 (proj)
MVC App 2 (proj)
'Common Presentation Layer Files' (solution folder)
other projects (projs)

How can one develop a rapid prototype for a web site while still using ASP.NET MVC?

I am developing a website in which I want to use ASP.NET MVC 5 because the site has the potential to be quite large and require the separation of concerns that MVC provides. However, the client wants me to show him a "prototype" of the home page which is simplay a single page that shows an image, some text, and requires a user login (and he wants to see it ASAP). How can I reconcile the fact that developing a proper ASP.NET MVC site requries a large amount of initial time to set up with my requirement to quickly put together a page to show my client what he has in mind? Should Also, should I consider using Web Forms over Razor for this initial part of the site?
You can prototype it fast just by modifying default view, without creating models controllers etc.
Login functionallity exists out of the box in MVC.
You can download one of MVC templates from Visual Studio.
Select File > New Project > Online > Templates.
You can find them also here (most of them are kept are up to date): https://visualstudiogallery.msdn.microsoft.com/site/search?query=mvc&f[1].Value=mvc&f[1].Type=SearchText&f[0].Value=templates&f[0].Type=RootCategory&ac=4
The Visual Studio Single Page Application template is super quick to setup. It'll run right out of the box. Just add your image and text to the Home view.

Get Html from Web page and create Setup project for Wpf Application (C#)

I'm trying to create a wpf application such as a movies library because i would like to manage and sort out my movies with a pretty interface.
I'd like to create a library with all my movies getting information from the web, but i don't know how very well.
I thought to get the information from a web site, for example imdb, but i don't know if it's legally to capture html from page to get the nested information.
It's my first desktop application and I would also like to know if it is necessary to create a database within the project and then create a setup project with specified script for deploy it.
Sorry for the confusion but i would like to know too much things :)
Thanks a lot in advance.
The legality of web scraping is a grey area. See my question, "Legality of Web Scraping vs Normal Use" and the corresponding answers for some insight.
Even if the legality is not a problem, web scraping is a flimsy approach because the webpage structure may change without notice, making your application suddenly useless until you update it to the new format. You are much better off using some sort of web API (if the site providing the information offers it).
Whether you need a database or not depends entirely on what your application will be doing and how you design it - it's not something any of us can tell you.
Same goes for the setup project - in fact I wouldn't worry about that until you actually have a working application. Take it step by step and keep the scope within control.
Yes I did not think about api.
It's a great idea, maybe use "themoviedb".
But if i create an application based on it, that has to show all the movies that you have stored on your hdd and get , for example, the posters, the description and the ranking, i have to create a database according to you?
Thanks a lot.

Migrating Public Website Slowly

I am currently working on a website that was built on C# from the 2003 period using server controls, javascript without libraries like the modern age a lack of a data access layer and plenty of spaghetti code.
We have decide due to the sheer size of the web site we will have to migrate web pages peices at time.
The problem is we have links, navigation and menus that need to point from an old domain where the legacy pages are to the new domain where our new MVC 4, BootStrap and clean greenfield rewrites of these legacy pages are being created. The problem is also that the new web pages will have links, navigation and menus that will have to point back to the old site as well.
I know I can create 302, I can use URL rewriting even.
My concern is that all developers will need to keep track of links both in the massive legacy website to the new website and update the urls manually.
Is there a simple way of migrating a website slowly?
Is there an approach I should research to handling this?
Should I stop snivling and just tell everyone on my team to keep track of the links as they go along and use something like wget on the legacy site to find all the links?
I would create a central repository for all the links, an XML file would do nicely, where both new and legacy sites would refer to get the URLs for the links.
Yes, you would need to change all links in both new and legacy to use this repository, but the upside is that once a page has been changed you can just change it's URL in the repository and all the links in both sites would now change.

Creating a MVC mobile site with same model and controller as main site

I want to produce a mobile site for a client, based on their existing ASP.NET MVC 3 Azure implementation. I'm happy that I can use the existing controllers and models, but I want a new set of views, JS, style sheets, and static content, that display less of the data. I'm pretty certain I can do this with just view changes.
Is there any way in which I can achieve some sort of view switch to pickup a different set for the mobile URL m.clientname.com - or even switch them at build time?
Can I product a view only project? And link in the DLL's from the main project ?
I guess the last resort is starting a new project based on the same files, but with new views?
Any thoughts on if anyone has done this would be appreciated.
This was covered by Scott Hanselman a while ago:
http://www.hanselman.com/blog/ABetterASPNETMVCMobileDeviceCapabilitiesViewEngine.aspx

Categories

Resources