MVC :: Storing Controllers & Views In Separate Assemblies?

Apr 14, 2010

I'm building a CMS type of application in MVC. I want to reuse my views and controllers for adding/managing content in at least two other MVC sites. Obviously I dont want more than one code base for the CMS stuff. I figured out a way to do so:

Controllers:

Controllers are easy. Nothing more than creating a new Class Library Project and adding your controllers. Be sure to reference System.Web.MVC. In your MVC project just reference your controller assembly.

Views:

Views are a bit trickier. My solution was to add the folder structure to my assembly

CMSViews
CMSViewsWhatever

Then start adding my view pages. For each page, you have to set the 'Copy to Output Directory' to 'Copy Always' (right click -> properties)

Then I created a new class which inherits from 'WebFormViewEngine'. In the constructor I call the base() and then I add paths to the base.MasterLocationFormats and base.ViewLocationFormats to specify the new locations to look for views.

[Code]....

Setup in MVC project:

To get the controllers and views to work from the assemblies, you have to add two lines of code in the global.asax. Under the RegisterRoutes() method, add

ControllerBuilder.Current.DefaultNamespaces.Add("YourAssemblyNamespace.Controllers");
then under the Application_Start() method add:
ViewEngines.Engines.Add(new YourAssemblyNamespace.MyViewEngine());

What I dont like is that the Views get put into the Bin directory when published and you have to make sure to set the Ouput to Copy Always which is going to be a PITA for larger projects with lots of views.

View 1 Replies


Similar Messages:

MVC :: Reference Views From Another Assemblies?

Mar 15, 2010

we have an asp.net web site (web application project of vs 2005) where we have a main project and same secondary projects which contain same apsx/ascx used by the main project.

for example in an aspx page of the main site we will use same ascx defined in another project)

at least with vs 2005 we must do a lot of hack to make it works becouse it's not possible to directly reference another web application to use aspx/ascx defined there.

i want know if upgrading to vs 2010 and mvc can help us to a better organization of this type of architecture (the best things will be if i can add a view as embedded resource of a project and i can use it by another project, as the server control of asp.net form)

View 3 Replies

Can't Get New Controllers Or Views To Work In .Net MVC

Apr 19, 2010

Basically what the title says. I created a new MVC application. I'm trying to add new pages to the site, but anytime I do I get the following error:Server Error in '/' Application.The resource cannot be found.Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

namespace MyAppMVC.Controllers
{
public class ProductsController : Controlle{
public ActionResult Index()
[code]...

View 3 Replies

MVC :: Splitting The Views And Controllers?

Jan 20, 2010

For applications that need to have fastly different view layers, and I would like to still use the idea of the controller. I would ideally like to but the controllers in a Class Lib. and then have only the Views in a MVC Web Application. Taking the model out in this way works well, but I can't find a nice way to split the views and controllers.

View 7 Replies

Assemblies - Embed Js / Css Images Into Separate Assembly To Read From Website

Sep 3, 2010

I'd like to create a class library project where embed resources like js, css and maybe image files. I would compile it and copy the dll into the bin folder of my web site to include the resources into my pages with GetWebResourceUrl.

I tried with an assembly that have no .cs files, but it doesn't seem to work, I can't see the namespace of the assembly in the web project.

View 1 Replies

MVC :: Views And Controllers Events Linked?

Jan 7, 2010

I am new to MVC. my question is when we add a view to the controller event by doing the right click and add view.then we give a view name and click on add button. where is this information stored that which view is linked to which view?

View 2 Replies

Creating Separate Models And Controllers Projects

Jan 22, 2011

I am reorganizing my MVC app into a Models project and a Controllers project, and then the main application as a project. So, everything is working good so far except. Whenever I go to "Rebuild" my controllers project, I get this error:
Controllers.AccountController.Initialize(System.Web.Routing.RequestContext)': no suitable method found to override.

Keep in mind that AccountController.cs was automatically placed in my application by Visual Studio, and this was all working fine when the Controllers were within my main project. I think it might have to do with the ASPNETDB.MDF file that this AccountController.cs file references to authenticate users as they log in, since this database stayed within my main project and didn't follow the Controllers project.

Here's the Initialize method on my AccountController:
protected override void Initialize(RequestContext requestContext) {
if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
if (MembershipService == null) { MembershipService = new AccountMembershipService(); }
base.Initialize(requestContext); }

View 2 Replies

C# - Attaching Validation To EF Objects Used In MVC Controllers/views?

Feb 11, 2011

We're throwing together a quick project (CRUD forms) and decided to skip view models and use EF entities directly in controllers and views. Since I'm not used to this approach, I'm confused about handling validation.

For example: a DB field has a length of 25. How does that get transferred (if it can) to a validation constraint in my view? If i was using an intermediate model, I would attach attributes to the model properties and it would work. How would I do this using EF objects directly?

View 3 Replies

C# - MVC Routing: Change Views For All Controllers In A Directory?

Jan 15, 2011

I have a subdirectory in Controllers named Admin, which contains several controllers.

Is there a way to change the route so that I can put all the views in "/Admin" for every controller in the Admin directory? Or do I need to map a route for every single controller?

View 1 Replies

Host .NET MVC Controllers+views Within A Webforms Project?

Jan 20, 2010

We have a legacy ASP.NET webforms application that we're engaged in stabilising and removing technical debt from. Is it possible to take a hybrid approach - ie, can ASP.NET MVC coexist with webforms within the same web-project? Are there any gotchas for that? If it is possible, I assume one just has to initialise the routes table, register the ASP.NET MVC handlers,

View 1 Replies

Grant Access To Controllers / Views For Non-authenticated Users?

Feb 3, 2011

I have an MVC 3 application which uses asp.net authentication. I have just created a custom errors controller and a couple of views for unknown errors and 404's. This works fine when I am logged into the application but if an internal server error happens during logon I would like to display the error/unknown view. However I just keep getting redirected back to the login as I am not authenticated.

I have added a location path for 'Views/Error' to my Web.config to allow access to all users but I am guessing it's the controller access that is causing the redirection.

Is there any way you can allow this in MVC or do I need to think of another solution? Just did not want to add a generic message to the login page as that's what my unknown error view is for.

View 2 Replies

MVC :: Creating Table Records With Foreign Key Constraints / Separate Controllers?

Oct 3, 2010

I have multiple tables that are all linked back to a central table with foreign keys. I want to be able to create a new record in table 2, but I'm having trouble because I don't know how to create a new instance of table 2's record while referencing the ID of the record it will be tied to.

EXAMPLE:

Database: Collection
Table: Collection Field 1: id Field 2: name
Table: Book Field 1: collectionId Field 2: id Field 3: name

Now, I don't want to be able to create a book without setting it's collectionID, but I can't figure out how this should be divided in the controllers/views.

Should Book have a controller separate from Collection, or should the Collection controller have a createBook method, separate from it's own create method?

I want to call the createBook method (from it's own controller, or the Collection controller) from the Collection Details view.

When I invoke the create method of Book, how do I create a new Book that is instantiated with the collectionId set from the details view of the Collection item that was listed in the details view?

I should point out, I'm using the entity framework for my model, and I'm definitely new to this.

View 2 Replies

MVC :: UML Class Diagram For Application Include All The Controllers And Views And Their Relationships?

Mar 16, 2011

I would like to ask a plain and simple question about the Model-View-Controller architecture - should the UML Class diagram for my application include all the controllers and views and their relationships, or should it just include my model classes, i.e. the entities that are the heart of the application, you know - like in an ordinary application - i.e. User, Administrator, Student, Teacher, Course, Grade etc...?

View 1 Replies

Php - MVC Architecture Decision - Refactor Existing Approach Into Controllers / Views And Database Access

Feb 12, 2011

Consider the following scenario: Page written in classic ASP or PHP, which is rendering a data report (series of HTML tables for simplicity). There is one main database query and then multiple sub queries as the page renders. The report is split into sub panels, which correlate to a sub query. Therefore:

Main database query. Loop over result. For each row, execute sub query and render report panel. How would you architect a similar report using the MVC pattern? This can be split into two parts: Efficiency at database level of multiple queries, which are dependent on values from an outer query. If all data was processed and prepared in the controller, would this also be deemed inefficient if looping within the controller and then again in a view to render. Could sub controllers be used or sub panels, which encapsulate smaller sections of logic i.e. loading data and rendering report panel.

View 2 Replies

MVC 2 - Views In Separate Assembly - No Intelligence

Feb 17, 2010

I have two projects in my solution: a) MVC Application b) Class Library. The class library acts as a plugin, so it contains views. The main problem is that I have no intellisense in the view's markup for my classes contained within the class library (the same assembly as the views). In the beginning I couldn't even write <%= Html.RenderAction... %>. I've solved that by adding a Web.config file to the class library with the following section:

<configuration>
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
</system.web>

Now it recognizes Html.RenderAction, etc in the view's markup. However I've no idea how to get access (with intellisense) to my classes contained within the same assembly as the views

View 3 Replies

Architecture :: Use Separate Pages Or Make One With Multiple Views?

Nov 15, 2010

I'm working on a webforms aspx app (not MVC) and I'm not sure if I should just create separate pages or somehow make multiple views on the same aspx page for the following scenario: Basically, I need to give the user the option to view a set of data a few different ways (essentially different group by's from a data perspective)... the data is always the same, its just a matter of how to arrange on the page...

each way I need to present the data will essentially consist of 2 repeaters, one nested inside the other. The outer repeater will display a nice header section with the nested repeater showing the list of items under that heading. view by book title (title is outer repeater, with the book list being the nested repeater, yes, multiple books with same title for this example - the app has nothing to do with books, this is just to illustrate)

Book Title: A Good Story
Author - Publisher - ISBN
Dan Johnson - Smith Publishing - kjdkjfd99898989
Susan Day - Smith Publishing - aa777fd99ff
Greg Greger - Corp XYZ - amkj897hgrt554

Book Title: Another Good Story
Author - Publisher - ISBN
Frank Franky - Corp XYZ - kj3kjfd9d9980
Jason Cambel - Smith Publishing - 7g7fddddttt
Jill Breker - Smith Publishing - d9ddt523321

Or, view books by publisher (here the publisher would be the outer repeater and the list, with different fields compared to first view, is the nested repeater.

Publisher: Smith Publishing
Title - Author - ISBN
A Good Story - Dan Johnson - kjdkjfd99898989
A Good Story - Susan Day - aa777fd99ff
Another Good Story - Jason Cambel - 7g7fddddttt
Another Good Story - Jill Breker - d9ddt523321

Publisher: Corp XYZ
Title - Author - ISBN
A Good Story - Greg Greger - amkj897hgrt554
Another Good Story - Frank Franky - kj3kjfd9d9980

so what do I do here? Just making separate pages is simple and would work, but is there something else I should be considering? There will be 3 different views, so 3 pages total if I went that route. Something is making me think I should be doing this all within one aspx page? maybe just toggling the visible property of the repeater controls? but then I was thinking each of these repeater controls is databound, and I assume even if they are not visible they still incurred database hits to get the data, right? and that could be bad?

View 4 Replies

Forms Data Controls :: Aligning Columns Of Two Separate Grid Views?

Jun 10, 2010

I am using two Grid Views to display data. One (headersGV) is used to show custom headers which change depending on the device type in the second table (dataGV).

The second displays device data and is bound to db tables. This table has a sort mechanism enabled, the functionality of which is in the header cell of the table, hence the need for the headerGV for column headers.

I need to align these two seperate tables so that the headers align with the data columns in the other table. The dataGV columns dynamically resize depending on the data displayed.

I have tried inline styles, css bound to both tables at different levels of priority, onbind methods, and overriding DataBind() method.

View 6 Replies

C# - Transferring Info In A ViewModel Between Views And Controllers In MVC 2 Site Without Allowing Modification Of Info?

Jul 22, 2010

I'm building an ASP.NET MVC 2 site where I'm currently implementing an OpenID sign-up form. Unfortunately, I'm foreseeing a possible security bug/vulnerability inside my architecture.

Here's how I want OpenID login to work:

User requests /Account/Login, Controller sends back OpenIDLogin View. User enters their OpenID into the View, then OpenID authorization takes place, and finally the OpenID is returned to the Controller.The Controller checks whether the OpenID is currently in use by a user in the system or not. If it is, the user is logged in to that account. If not, the registration process begins.

And now, the OpenID registration process:

The OpenID identifier, as well as any other information provided by the OpenID provider (such as email address or name), is put into my custom ViewModel and sent to my OpenIDRegistrationForm View.The RegistrationForm View stores the OpenID in a hidden field to make sure that it gets sent back to the Controller.The user fills in the RegistrationForm View and sends it back to the Controller.The Controller creates the user account and puts the OpenID into the database.


The bug that I see within my architecture is that a user could modify the hidden value in the RegistrationForm View. Thus, they could spoof their OpenID! I will make sure to add another round of checking to the final Registration Controller Action to make sure that the OpenID that is provided doesn't exist yet, but there is still a possibility for spoofing. Can my architecture be improved somehow? I don't want this to end badly...

One solution I'm considering is encrypting the OpenID before I send it to the View and then decrypting it when it reaches the Controller. Should I try this?

View 1 Replies

MVC :: Routing - Seperate Controllers With Seperate Views ?

Apr 29, 2010

Here is what i would like to be able to do with the urls/routes:

1) www.domain.com/customer/home/index

2) www.domain.com/home/index

Where both the home controllers should be seperate controllers with seperate views and the company part should be an param for all the actions in the controllers.Now why i want to be able to do this is because of the following scenario: Each customer will have there own pages (which actually will all be the same for each customer but with different information per customer). The one without the customer is the general website where non customers can go to to become an customer or get information about the services we provide for them, they can sign up etc.

View 5 Replies

Forms Data Controls :: Need The Complete Code For Storing The Entered Data In Both The Views Of The Multiview Control After Hitting The Submit Button?

Feb 3, 2010

I have webpage containing 3 views of multiview control. In the first view there are 3 fields Name Age Surname
which will be captured in the textbox for the respective fields.In the second view i have three more fields

sex
maritalstatus
bloodgroup

which will be entered in the respective textboxes and a submit button to store the data in both the views in the sql server database. I have all the fields in the sql server table which are mentioned in the webpage.I need the complete code for storing the entered data in both the views of the multiview control after hitting the submit button.

View 1 Replies

Configuration :: What Is The Diff Between Link To Assemblies In Project File And Assemblies In Web.config File

Apr 30, 2010

when I reference a assembly. It's reference gets added to the project file in my case ( ABC.csproj)

Also when I take a look at the web.config file there is a section called <assemblies>. And lot of assemblies are added there.

What is the difference between link to the assemblies in the Project file and the assemblies in the web.config file?

View 1 Replies

DataSource Controls :: Display Results From Two Separate Tables In Two Separate Databases?

Jan 14, 2010

I have access to two seperate databases (mySQL) located on two servers. I need to get the data, link the tables on a key field and display the results in a datagrid. My challenge is that if the search criteria changes for the display it affects rows returned from on table and should thus automatically affect the linked table and resulting data returned.

what the best approach would be to achieving this? So far I have set up a dataset with a dataadapter and table for each connection and then linked the tables in the dataset. The problem that I'm having is getting the linked resultsets to work.

On my form I have the datagrid with two Objectdatasources one for each dataadapter and i believe that's where I'm going wrong...

View 1 Replies

Added 5 Views In The MultiView But All Views Are Tight Together?

Sep 28, 2010

I am learning MultiView control.Here are question:I added 5 views in the MultiView but all views are tight together. I can not drag and drop another control such as text boxes or labels into view area.

View 15 Replies

Storing A Uploaded File In DB Or Storing It In Filesystem?

May 11, 2010

I have a File Uploader in my ASP.NET application Using C#, we can upload any type like images, documents, pdf etc.

I m storing it in the Filesystem and having only the Name of the File in DB.My doubt is can we store the entire file, images in DB. State me Which is good practice and why we need to use it.

Either file System Storage or SQL DB Storage.

View 4 Replies

MVC :: How To Separate Project Into Separate Layers

Feb 2, 2010

I am beginner to ASP.NET MVC.

We are doing project in Asp.Net MVC and Nhibernate.

How to seperate my project in to layers ? how to design classes ?

should i followany patterns ? repository patterns ?

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved