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.


1 Comment on ASP.NET MVC, good or bad?

  1. spootwo says:

    Conditional code needs to be pushed back into the controller. The page deals with displaying data, so \’if\’ need to be resolved before the view state.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>