Archive for the ‘ASP.NET MVC3’ Category

Like i had anouced in my last post yesterday i had been the speaker in a session about Web and Cloud Development at the Launch event of Visual Studio 2012 in Portugal.

After my session some questions had arrived to my email. On off the most common questions was if ASP.NET MVC will kill ASP.NET WebForms. That was what made my write this post in the reality each technology has is one scope and is better at something i use them both depending on my goals.

Let’s take a look at the advantages of each one

Advantages of an MVC-Based Web Application

  • It makes it easier to manage complexity by dividing an application into the model, the view, and the controller.
  • It does not use view state or server-based forms. This makes the MVC framework ideal for developers who want full control over the behavior of an application.
  • It uses a Front Controller pattern this enables you to design an application that supports a rich routing infrastructure.
  • It provides better support for test-driven development (TDD).


Advantages of a Web Forms-Based Web Application

  • It supports an event model that preserves state over HTTP, which benefits line-of-business Web application development. The Web Forms-based application provides dozens of events that are supported in hundreds of server controls.
  • It uses a Page Controller pattern that adds functionality to individual pages.
  • It uses view state on server-based forms, which can make managing state information easier.
  • In general, it is less complex for application development, because the components (the Page class, controls, and so on) are tightly integrated and usually require less code than the MVC model.

For my point of view this is the most relevant points of each technology. Another point off choice can be the size of the development team envolved. If you have big and multidisciplinar teams MVC is better if you have produtivity issues and a very small team and you don t need to have full control of front end WebForms will be the winner.

I hope this post help you when you are looking for chose the right aim in the Microsoft Web development stack.

Any Question feel free to contact me.

I had been spending a great part of the night trying to figure out how could i automatic generate Controls and views in ASP.NET MVC 3 and i end up with a review to code first way to do things.

My problem was to allow some dynamic content to be manged directly from a website. For my example i used a canonical example based on books.

So here goes the review of automatic creation to the ones like me that don t remember sometimes this wonderful MVC 3 feature.

After long running R& D and tests i finally can do this. To do that i had to use some CRUD with scaffolding with Entity Framework and code first. So let’s meet my road to accomplish this.

Step1: Before sacaffolded, i create a model and a DbContext to define what data will be collected.  So i create the following classes

public class Book
public int ID { get; set; }
public string Title { get; set; }
public string Isbn { get; set; }
public string Summary { get; set; }
public string Author { get; set; }
public string Thumbnail { get; set; }
public double Price { get; set; }
public DateTime Published { get; set; }
public class BookDBContext : DbContext
public DbSet<Book> Books { get; set; }

The first class defines the concept of book and his data and actions. The second class is the context of book.

Step2: Create the model

i had use the right click of the mouse in to the Controller folder of my project and select Add Controller visual studio opens the window

This is a great way to quickly put your entities and elements running