Click here to Skip to main content
13,250,043 members (68,357 online)

Welcome to the Lounge

   

For discussing anything related to a software developer's life. Technical discussions are encouraged, but click here to ask your programming questions.

The Lounge is rated PG. If you're about to post something you wouldn't want your kid sister to read then don't post it. No flame wars, no abusive conduct, no programming questions and please don't post ads.
 
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
AspDotNetDev16-May-12 7:39
protectorAspDotNetDev16-May-12 7:39 
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
dave.dolan16-May-12 18:06
memberdave.dolan16-May-12 18:06 
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
AspDotNetDev16-May-12 19:31
protectorAspDotNetDev16-May-12 19:31 
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
ahmed zahmed14-May-12 11:53
memberahmed zahmed14-May-12 11:53 
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
Matthew Dennis14-May-12 15:37
staffMatthew Dennis14-May-12 15:37 
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
AspDotNetDev14-May-12 16:00
protectorAspDotNetDev14-May-12 16:00 
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
Matthew Dennis14-May-12 16:38
staffMatthew Dennis14-May-12 16:38 
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
Matthew Dennis14-May-12 11:54
staffMatthew Dennis14-May-12 11:54 
The problem with moving from Web Forms to MVC is that it is a different architecture and requires you to think about your application is a different way.

Web Forms is Microsoft's way of making a stateless protocol, HTTP, appear to have state. They do this by storing a the page state in a hidden value so it is available to the server on Postback, and then simulate the event architecture that is familiar to Windows Forms (VB) programers. The page gets control first and there is one 'code-behind' for each page.

MVC, on the otherhand, requires the developer to get their hands a little dirtier, and work with the 'low-level' HTML. Your web pages should only be responsible for displaying/formatting the data passed in in the Model. The Controller is responsible for getting the information, building up a Model and passing it to the page for display. The controller gets control first, and each controller is the 'code-behind' for multiple Views (pages).

Additionally, ASP.NET MVC will parse out your Form Data, to build up instances of classes for you, along with validating the information for you. This greatly reduces the amount of code you need to write, and helps get you business logic out of your presentation layer.

As for re-useable components, MVC supports re-use of UI in varioius ways:

  • Code Generation Templates - by using intellegent code generation templates you can create
    Views, Partial Views, Classes, almost anything you want. MVC even allows you to plug in your own custom template and they will be included in the list of View types. Similarily, you can have templates for Controllers, so you could have Controllers that use the Repository Pattern, use Entity Framework, implement a Web API, etc.
  • Display and Edit Template - you can create templates that control how classes are rendered when using the @Html.DisplayFor or @Html.EditorFor helper. For example, you could have all Date fields use a JQuery UI DatePicker.
  • Partial Views - Allows you to create a page for rendering a piece of the UI, not the whole page. They are similar to UserControls in this manner, but remember, it is the Controller, not the page that handles the Http Requests. Partials can be passed an object which acts as a Model for the page implementing the Partial View.
  • Render Action - Allows the View to cause a new instance of a Controller to be spun up and a method called to generate HTML for the main page. This means that the new Controller does all the work to build up the component's Model. The main page does have to supply this data. This is probably as close to the WebFrom UserControl as you will get in MVC, but MVC pureists tend to frown on it as they feel that the View should not be calling back to the Controllers. IMHO, if it does what you need to be done, consider using it, just understand the consequnces.
  • Third-Party Helpers - A number of UI component vendors have created HTML helpers to generate all sorts of UI, from plugging in JQuery UI, Grids, Twitter Feeds, Maps, Graphs, etc. This is available open source, free, or comercially licenced. Telerik, DevExpress, Microsoft and others offer free versions. There are libraries available on CodePlex, Google COde, and GitHub that are quite impressive.


Most of the above can function without JavaScript (of course the JQueryUI stuff requires it).

Talking about how MVC makes AJAX enabled pages easier is a whole series of article, not a forum post.

All that said, was there a specific task you were trying to accomplish? I would be glad to help you wrap your brain around doing it the MVC way. Then you can decide which way to go.

Just to muddy the waters a bit, you can mix WebForms and MVC pages in the same application. Use what works best for what you are trying to do, and who is trying to do it.

Matthew Dennis
Senior Architect
The CodeProject.
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
Keith Barrow14-May-12 12:05
mentorKeith Barrow14-May-12 12:05 
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
AspDotNetDev14-May-12 12:33
protectorAspDotNetDev14-May-12 12:33 
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
Keith Barrow14-May-12 13:31
mentorKeith Barrow14-May-12 13:31 
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
Matthew Dennis14-May-12 16:30
staffMatthew Dennis14-May-12 16:30 
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
AspDotNetDev14-May-12 18:44
protectorAspDotNetDev14-May-12 18:44 
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
Matthew Dennis15-May-12 4:25
staffMatthew Dennis15-May-12 4:25 
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
AspDotNetDev15-May-12 16:33
protectorAspDotNetDev15-May-12 16:33 
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
dave.dolan16-May-12 2:44
memberdave.dolan16-May-12 2:44 
General[Long post] MVC: For Those Who Don't want to fight the way the web actually works. Pin
Keith Barrow14-May-12 13:06
mentorKeith Barrow14-May-12 13:06 
GeneralRe: [Long post] MVC: For Those Who Don't want to fight the way the web actually works. Pin
AspDotNetDev14-May-12 13:33
protectorAspDotNetDev14-May-12 13:33 
GeneralRe: [Long post] MVC: For Those Who Don't want to fight the way the web actually works. Pin
Keith Barrow14-May-12 13:52
mentorKeith Barrow14-May-12 13:52 
GeneralRe: [Long post] MVC: For Those Who Don't want to fight the way the web actually works. Pin
AspDotNetDev14-May-12 13:37
protectorAspDotNetDev14-May-12 13:37 
GeneralRe: [Long post] MVC: For Those Who Don't want to fight the way the web actually works. Pin
Keith Barrow14-May-12 13:43
mentorKeith Barrow14-May-12 13:43 
GeneralRe: [Long post] MVC: For Those Who Don't want to fight the way the web actually works. Pin
BobJanova15-May-12 0:47
memberBobJanova15-May-12 0:47 
GeneralRe: [Long post] MVC: For Those Who Don't want to fight the way the web actually works. Pin
Keith Barrow15-May-12 3:56
mentorKeith Barrow15-May-12 3:56 
GeneralRe: [Long post] MVC: For Those Who Don't want to fight the way the web actually works. Pin
Flynn Arrowstarr / Regular Schmoe16-May-12 9:14
memberFlynn Arrowstarr / Regular Schmoe16-May-12 9:14 
GeneralRe: ASP.NET MVC: For Those Who Dislike Reusability Pin
Roger Wright14-May-12 19:05
memberRoger Wright14-May-12 19:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy |
Web04 | 2.8.171114.1 | Last Updated 19 Nov 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid