Using Autofac in a ASP.NET MVC 4 application

Posted by – October 18, 2012

ASP.NET MVC is a great framework, very flexible, but sometimes we need to organize a little better our business logic, there’s nothing better than have a business logic completely decoupled from controller, which can be easily reused on several controllers over the project.

To help ASP.NET MVC make use of reusable business logic and other logic components aswell, we can add a DI/IoC container to our project, after few days researching about IoC container alternatives, I choose Autofac to create my first web application that takes advantage of Dependency Injection.


Fixing SelectedValue issue on DropbDownListFor with SelectList

Posted by – July 30, 2012

After spent several hours trying to figure out how the SelectedValue works on DropDownListFor, I finally figure out how to do it, you can also check my answer on stackoverflow here.

It’s very simple to get SelectList and SelectedValue working together, even if your property isn’t a simple object like a Int, String or a Double value.


Assuming our Region object is something like this:

public class Region {
     public Guid ID { get; set; }
     public string Name { get; set; }



Data Persistence on ASP.NET MVC Applications with EntityFramework

Posted by – February 27, 2009

There’s no doubt, ASP.NET is an amazing technology, very productive and easy to use, but it isn’t perfect, his architecture doesn’t help enough when you need add unit tests in your project and you can’t see a clean separation of concerns, some of its urls used to access pages isn’t so intuitive, if you need pass some data over browser address bar it will only read by accessing the old QueryString object.

As completly opposite we have ASP.NET MVC, some of its urls are very intuitive, you don’t need use something like QueryString object to read parameters passed via GET method, you can see a clear separation between model, view and controller layers, all ASP.NET MVC applications can be easily tested using the most famous unit tests frameworks.

In this article I’ll give a small introduction to web development with ASP.NET MVC and data persistence using ADO.NET EntityFramework, a simple contacts application will show how to accomplish this.


ASP.NET Basics with Visual Studio Web Developer 2008

Posted by – January 8, 2009

ASP.NET is one of the key technologies behind .NET Framework, you can easily create web applications to collect data entered by user by placing some input controls in your page, once the data is entered and the page is submited, you can read data on server side by accessing specific properties in your controls.

This article will give an idea about how to create a simple ASP.NET project, it will have a page that contains some textboxes and a button, this button will have an event attached to it, we will add some code in this event to store user entered data into an SQLite database using its ADO.NET provider that can be downloaded here.

I’m assuming that you already have installed Visual Studio Web Developer Express 2008 in your computer, if not, you must download both from this site.

Now you must start Visual Studio Web Developer Express 2008 and then go to File->New Web Site… menu like we have in the image below:



ASP.NET MVC, good or bad?

Posted by – March 15, 2008

I have been listening some screencasts about ASP.NET MVC, at first moment we can see few features found on the other web frameworks like Grails and RoR, the controllers are very easy to write and all controllers actions can be bind easily on your view code by using helper methods.

The default view engine of ASP.NET MVC is terrible, remembers the way that we wrote some ASP and PHP pages in the past, if you need more control over page rendering you must place some conditional statements there, take a look on the code block below:

<form action="/App/InsertCustomer">
  <% if (ViewData.ErrorMessage != null) { %>
    The following error occurred while inserting the customer data:
    <br />
    <%= ViewData.ErrorMessage %>
    <br />
  <% } %>

  First name: <input type="text" name="firstName"
      value="<%= ViewData.FirstName %>" /><br />
  Last name: <input type="text" name="lastName"
      value="<%= ViewData.LastName %>"  /><br />

    <input type="submit" value="Insert" />

Note the presence of ASP tags <%= somecode %>, this kind of web page code can be very easy to understand on small pages, but if your pages start to be bigger and bigger you will have some problems with code readability, I don’t like this kind of view coding, it can turn into a nightmare.

But, in other hand, you can put all this mix of markup and C#/VB code into an ASP.NET user control, separating small pieces of reusable code into .ascx files, with this approach you can reduce the amount of non markup code into your page and all page rendering logic will be a little more easier to understand.