How to use ASP.NET MVC Master Pages Solution in Individual ASP.NET MVC Projects - asp.net

We have an ASP.NET MVC project to serve as a master portal. The portal has links to controllers/views in other ASP.NET MVC projects. When the link is clicked, we want to a view from a different MVC project is loaded into the body of the master portal.
We know ASP.NET MVC provides Area within the MVC project to organize related functionality into a group functions. But instead everything in a project, we prefer to have related functionality into a separate project but they share the same master portal.
Is it doable within ASP.NET MVC and how?

Depend on what is your exact requirement,
If you want to share only data between projects expose controller
actions and share the data by means of JSON.
Sharing UI between project may not come handy in the long run.
Before anything, have a look at this article
Always there is way to do everything in programming, but consider performance and best practices to keep your application long living.

Related

Design a CMS site using ASP.NET MVC 5

I'm building a site which mainly has articles and I'm using ASP.NET MVC 5 framework. I want to have an admin page where I can add, edit these article content.
I'm having a problem with designing the structure of this project.
I'm thinking of having a controller class called 'adminController', where I handle all the requests related to content management.
Is that approach conceptually correct in ASP.NET MVC? Because If this was an ASP web forms project, I would simply have two different projects called Public and Admin in a single solution.
I'm quite new to ASP.NET MVC framework and I'd appreciate any help.
You can do 2 separate projects and can do one.
Since ASP.NET MVC 4 whe have Areas and i suggest you to use it if you want structure your project and separate admin logic from public.
Here is a tutorial that you can check that explain whar areas is and how you can work with them.

Importing an ASP.NET website application to views in an MVC application

I have created an ASP.NET website with several aspx webpages and a masterpage. I now want to port this website to an MVC application and use the aspx pages as views. How can I do this in Visual Studio 2012?
There is no automatic process you can use to do this. You will need to create the views/controllers/actions manually and cut/paste your existing code into these (unfortunately)
Their is no one click process. You need to do it manually.
I suggest you to create a MVC solution. put your logic in Models, And start rewriting Controllers and Views according to your previous asp.net apps. Because asp.net MVC 's rules doesn't allow Session and Viewstate you need to make changes to your existing apps.
You need to move from session and Viewstate if your current asp.net app use this things.

What is the difference between ASP.NET and ASP.NET MVC?

I'm a complete beginner when it comes to ASP.NET but I want to learn it in order to build a web application that eventually will communicate with a cloud hosted SQL server. However, I cannot find any information that outlines the difference between ASP.NET web application and ASP.NET MVC2 web application (in visual studio 2010) so I'm not sure where to start. Can anyone give me a simple explanation/outline so I can decide on a tutorial to follow?
Thanks
ASP.NET is a web platform. It provides a layer that sits on top of IIS (the web server) which facilitates the creation of web applications and web services. ASP.NET MVC is a framework specifically for building web applications. It sits ontop of ASP.NET and uses APIs provided by ASP.NET. ASP.NET Web Forms is another framework specifically for building web applications, and the new ASP.NET Web API is a platform for building web services.
ASP.NET, at its most basic level, provides a means for you to provide general HTML markup combined with server side "controls" within the event-driven programming model that can be leveraged with VB, C#, and so on. You define the page(s) of a site, drop in the controls, and provide the programmatic plumbing to make it all work.
ASP.NET MVC is an application framework based on the Model-View-Controller architectural pattern. This is what might be considered a "canned" framework for a specific way of implementing a web site, with a page acting as the "controller" and dispatching requests to the appropriate pages in the application. The idea is to "partition" the various elements of the application, eg business rules, presentation rules, and so on.
Think of the former as the "blank slate" for implementing a site architecture you've designed more or less from the ground up. MVC provides a mechanism for designing a site around a pre-determined "pattern" of application access, if that makes sense. There's more technical detail to it than that, to be sure, but that's the nickel tour for the purposes of the question.
Good luck!
ASP.NET MVC2 web application is based on MVC pattern in order to facilitate unit test, without mocking pipeline asp.net, because it's very difficult. you don't have code on Code Behind in order to separate your code graphic and your code functional.
With MVC your application become independent from view. you can replace easily technology of creating view.
Read this article it's very interesting : http://msdn.microsoft.com/en-us/magazine/dd942833.aspx
If you have VS10 make a small ASP.NET (webforms) application and a small ASP.NET MVC 2 application, and examine the differences between them. It's a great way to learn.
A very good material is available here
http://www.webdevelopmenthelp.net/2013/10/Difference-between-ASP.NET-WebForm-And-ASP.NET-MVC.html
Like ASP.Net web forms, ASP.Net MVC is development model to build web application in Microsoft .net framework. The major difference between them are ASP.net MVC is based on the MVC architecture. Where we have 3 independent tiers – Model, View Controllers which interact which each other to render HTML output.
Major differences
Web forms is mainly has an event driven model. Where we have page level events(Page_load, pre render, page_init etc) and control level events. Which is not the case for MVC. The request life cycle is comparatively complex.(why complex because, the request has to goes through all the events before rendering the HTML output )
Web forms is basically has an aspx page which contains UI controls and a code behind file. All the page level events and control level events are handled here. In MVC the View, Model , controller can exist independently (gives clear separation of concern)
The SOC makes it easier for development as we can have separate developers for View(design html) and controller (implement business logic)
Because of this tight coupling nature, web forms are not suitable for unit tests. In MVC we can write unit tests at both controller level, action method levels. Here we can mock the data to be passed to view and do assert the result from the action method for their different properties like view name, model properties, null check etc
In web forms we have state full behavior. The server controls in ASPX page uses view state to retain their state during request response cycle. Since this view states are stored as hidden controls inside the page itself, and they are sent during request and response cycle, it makes them more heavy. Absence of view state and state less nature of MVC make it more light weight. Hence they are much more faster in request lifecycle.
ASP.NET is a web platform. It provides a layer that sits on top of the web server which facilitates the creation of web applications and web services. ASP.NET is a framework specifically for building web applications. It sits of ASP.NET and uses APIs provided by ASP.NET. ASP.NET Web Forms is another framework specifically for building web applications, and the new ASP.NET Web API is a platform for building web services
ASP.NET is a 2 tier application in which no separate section for the database and MVC is a 3 tier application in which view and logic is kept separate.
In ASP.NET for each .aspx form one URL is generated, but in MVC the url's are generated based on the controller and by the router configuration.

How to create an ASP.NET MVC 3 control/component that can be reused by other applications

I am required to deliver a component, inlcuding business logic and UI, to be used on a ASP.NET MVC 3 web site that is being developed by other company.
I know my way around ASP.NET WebForms server controls and how to package and distribute them to be reused across projects. I also have experience with MVC approach in general and some ASP.NET MVC experience. I did read over materials recommending use of HTML helpers and similar, but most of this deals with only UI reusability or reusability inside a single ASP.NET MVC project. I did not find any mentions of how to package and distribute such functionality for ASP.NET MVC.
The business logic is major part of this component. It is supposed to be a kind of wizard, which progresses through a lot of steps and which would also work with database using Entity Framework and send an email to the user upon completion.
How would I go about creating a control/component that encapsulates complex business logic and also renders its own UI/view output and that would be distributable in form of a standalone assembly? Is this even possible or only to some extend?
Would this somehow be doable by wrapping model, view and controller inside an assembly?
Or would it be better to approach this just as a complex model? If so, how would it be possible to connect the UI/view and controller to this component by the consumer of the component?
I also did see a couple of vendors out there, such as Telerik, who sell something along the lines of ASP.NET MVC controls/components, so I assume this is somehow possible to do.
This article tells how to call controllers from another assemblies.
To reuse only views, you can use RazorGenerator.
I recommend you to refer the MVC Control ToolKit Project page of CodePlex
Also see ASP.Net MVC Sprite Project

Can "classic" ASP.NET pages and Microsoft MVC coexist in the same web application?

I'm thinking about trying out MVC later today for a new app we're starting up, but I'm curious if it's an all or nothing thing or if I can still party like it's 2006 with viewstate and other crutches at the same time...
Yes you can have your webforms pages and MVC views mixed in a single web application project. This could be useful if you have an application that is already built and you want to migrate your app from webforms to mvc.
You need to make sure that none of your webforms pages go in the 'Views' directory in a standard ASP.NET MVC application though. Pages (or views) in the 'Views' directory can't be requested directly through the url.
If you are starting an application from scratch, there would be very little benefit to mixing the two.
Yes. MVC is just a different implementation of the IHttpHandler interface so both classic ASP.NET and ASP.NET MVC pages can coexist in the same app.
As you've probably noticed with the above answers, yes this is very possible to do.
I've actually had to do this on my current project. I was able to get approval to add MVC to our application, but only in the administration section (to limit the risk of affecting current members coming to our site).
The biggest problem I had was converting my Web Site to a Web Application, but once that was done, things were pretty straight forward adding MVC side-by-side our classic code-behind web pages.
The trick for me was to make my MVC pages look as similar as possible to my code-behind pages so the transition looked as seamless as possible.
I am currently working on a new project. While I would like to go down the MVC route all the way, some of the project requirements don't allow me.
One of those requirements is to have a grouping grid from the client-side. Personally have chosen the Telerik Rad-Grid. While they may be in the process of supporting MVC they are not there as yet.
So this means that I have to have a hybrid solution. for the time being until RadGrid fully supports MVC.
While we are in this transition period I think that there will be may more hybrid projects out there until the support of the Third Party Controls catches up.
Regards
Nathan
You'll need to make sure your MVC routes don't conflict with your Web Forms pages so that requests for a .aspx page don't get routed to a controller action as a parameter etc.
See this blog post by Phil Haack for details on how to avoid this.
Yes, it is very much possible for MVC pages to coexist with asp.net web forms. I implemented that in my existing asp.net application for adding new features. We need to make sure of referring the MVC DLLs, registering routing tables for URL routing and configuring the assemblies and namespaces in Web.config file.
If you're mixing MVC with other methodologies you're not really getting the benefit out of it. The point of MVC is to allow you to decrease coupling and increase cohesion, and if only half of your code is doing that, then the other half is inevitably going to restrain your development cycle.
So, I guess while it's possible, I don't think it's worth it. Go all the way or don't go at all.

Resources