MVC 3 Cleaner Views

Hi,

Lets compare MVC 2 to a MVC 3 view, a basic one:

MVC 2:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PhotoRA.Web.ViewModels.StoreBrowseByEventViewModel>" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> 
</asp:Content> 

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 
    <h2>Browse Photo's</h2> 
    <ul>
    <%foreach (var photo in Model.Photos) {%>
    <li><a href="<%: Url.Action("Details","Store", new {photoId = photo.PhotoId} )  %>"> <img src="<%:photo.Photo_Url %>" /> </a></li>
    <%}%>   
    </ul>


</asp:Content>

MVC3:

@model PhotoRA.Web.ViewModels.StoreBrowseByEventViewModel
    <h2>Browse Photo's</h2>
  <ul>
    @foreach (var photo in Model.Photos) {
      <li><a href="@Url.Action("Details", "Store", new {photoId = photo.PhotoId})"><img src="@photo.Photo_Url" /></a></li>
    }
  </ul>

 

Pretty Clean….

There is also a @helper for HTML helpers and loads of other stuff such as layout defaults and better IoC/DI support.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s