Is Area what I am looking for? - asp.net-mvc

Hi I'm new to MVC2 or MVC in general. I'm gone do basic app with a backend. Now I been thinking about how I should do with the folders, views, controllers & routes for the AdminFolder. Now I just saw something called Areas. Is that a way to go for me?
http://haacked.com/archive/2009/07/31/single-project-areas.aspx

Sure - ASP.Net MVC 2 Areas is a nice way to organize your site into functional areas.
Suppose you have a site which needs the following sections:
Admin - manages the web site
Blog - a place to put in a blog
Account - a place for registered users to manage their own account
...
You can then consider each of those sections as "areas" of your application & organize them accordingly...
HTH.

Related

MVC 3 Domain Routing

I would like to know if the following is possible. I have a website called www.myweb.com. This website could be a directory of say football teams. The list of teams could be found here
www.myweb.com/home/teamlist
On selecting a team one would be take to
www.myweb.com/teams/teama or
www.myweb.com/teams/teamb etc
the content under the teams area would be related to them e.g.
www.myweb.com/teams/teama/fixtures
www.myweb.com/teams/teama/news
i have the above working but would like to know if it is even remotely possible to have a separate website for each team which still uses the current models, views and controllers e.g.
www.teama.com
would go to display the data from
www.myweb.com/teams/teama
where 'teams' is the controller and 'teama' is a parameter for a 'details' action. Also doing
www.teama.com/fixtures
www.teama.com/news
would display the same stuff as
www.myweb.com/teams/teama/fixtures
www.myweb.com/teams/teama/news
many thanks and hope i have worded it ok.
Rudy
I would consider using IIS URL Rewriting in that case.
Have a look at MVC Domain Routing, I'm still researching it myself as I have a similar required as yourself but I think that should do what you need.
The following links might be handy:
ASP.Net MVC Domain Routing
Bolt on multi-tenancy in ASP.Net MVC Part I (link to Part II is on the page)

ASP.NET MVC 2 Code Sharing

I have a solution which contains 2 MVC Website Applications (Website & Website Admin System). As I am progressing with the build there is a lot of common code especially in my View Models, HtmlHelpers etc. Is it good practice in MVC to treat these two sites as separate entities and keep code in one site specific to that site and manually copy code across to second site? Or is there a practice to share this common code across web apps?
It is just natural for me to refactor common code when I see it? However I am not so sure how this works within an MVC environment. Any suggestions or comments welcome.
You can create a class library project and push that code to that project. Then have both website projects reference that DLL. I believe views are about the only thing in MVC that you can't do that with. I believe you can do it with controllers too, but I haven't tried it.
If your sites are sharing many ViewModels and HtmlHelpers I'd take a step back and examine why they are two separate sites. Is the second one an Admin area of the first site, or is it a completely separate entity altogether? If the first, I'd probably have everything in one site. If the second, I'd do as Brian Ball suggested and create a library project that the two sites share.

Whats so great about the new MVC2 areas?

Could some one please explain the advantages and disadvantages of using the new MVC2 Areas feature?
I don't understand what is so great about them. If I am adding an admin area to my MVC application why not create a new Admin folder in the main Views and Controllers folder? What does creating an area really get me?
This is what Phil Haack says:
The scenario that areas address is
being able to partition your
application into discrete areas of
functionality. It helps make managing
a large application more manageable
and allows for creating distinct
applets that you can drop into an
application.
An admin section wouldn't qualify as an applet as it logically belongs with your application and may even share models with it.

asp.net mvc cms

I am little bit confused by the concept of cms in asp.net mvc application. The question is the following: How can I add controllers and some processing in the view page in the cms?
For instance in cms I create a page called "Account Details". For this logically I need a controller that would receive and process the request. The processing includes validation, db retrieval, etc. In the view part, I need a set of text boxes, etc. As I know, in cms I cannot create something like this. How to proceed in this way?
Best to look at some existing MVC CMS projects and see how they do it. Here is a thread on SO that covers some of the open source MVC CMS's.
Building a CMS in ASP.NET MVC
Check out the answers in this thread: Simple CMS for building a small company presentation-website.

ASP.NET cms and display template - 2 projects or just 1?

This is a ASP.NET MVC beginner question (I'm in phase of developing NerdDinner)... I have assignment to create ASP.NET MVC cms (with its own design) and portal (also with its own design) that will display data that's being handled by CMS. I was wondering if I will have to make two individual projects in Visual Studio or I will have to use one project and place portal section in specific folder.
I know that my question is a bit premature (according to fact that I still haven't finished tutorial) but I'm bit impatient :)
On server (commercial hosting) I would use only one hosting account... this thing with URL routing is a bit confusing to me, CMS is practically also optimized for SEO.
I would like to the structure of URL to be:
---- PORTAL ----
www.domain.com
www.domain.com/Menu1/Submenu1
www.domain.com/Menu2/Submenu1/SubSubmenu1...
etc.
---- CMS ----
www.domain.com/CMS
www.domain.com/CMS/Whatever
Thanks,
Ile
It all depends on the functionality of the portal and the MVC cms.
For starters I would have a separate solution for the Model/Data Access that way you can have as many MVC projects without duplicating your data access.
From your desired url structure I would probably have the CMS as a separate controller and sub folder. Alternatively if your using MVC 2 you could look at the areas support which will probably give you a little more flexibility.
If you want the solution to be a bit more complex/flexible you have a number of options:
If both the portal and MVC cms are going to have he same functionality and page layout you have two master pages and determine which mater page to show when returning the view. You would specify this in the routing so multiple routes would point to different controllers.
If the layout/functionality differs slightly but one controller can still manage both you could have a separate controller project and two mvc projects which only contains the views, javascript and images so both mvc solutions look at your controller solution. With this option you would probable end up setting up two websites on your domain one under the root and the other under the CMS folder (in your MVC app you will prob need to block routes to /CMS so it will be processed by your CMS app).
Finally if both differ hugely have two separate projects but keep your common data access project, as above you may need to set up two sites on your hosting package.

Resources