Introduction
MVC4 is really trying to break new ground in helping developers get to market more quickly and with a product that adheres to the emerging standards of today. A tough thing to ask of any technology, to be sure, but it's making some decent strides in the right direction.
Already the tutorials and blogs posts are popping up quicker than mushrooms on the midden heap. We highlight a few here that you definitely shouldn't miss which deal with key upcoming features...
ASP.NET MVC 4 Hosting
If you are looking for a QUALITY, AFFORDABLE host that supports ASP.NET MVC 4 Hosting, you can take a look at ASPHostCentral.com
ASP.NET MVC 4 Overview - Part 2
Jon Galloway goes into some significant detail here about some of the changes coming our way in the new version. He talks about the new default templates that come out of the box and the reasoning behind them.
He also talks about the new adaptive rendering taking advantage of CSS media queries and the usage of the viewport meta tag to help improve the mobile user experience. Overall a solid post that will stand the test of time. Check it out...
ASP.NET MVC 4 Bundling and Minification
Bundling and Minification of assets have to be two of the most tedious things to setup on a new web project. In this excellent post, David Hayden goes through exactly what you need to do to make the process as seamless as possible in MVC4.
Don't make the mistake of leaving this to the end of the project. You'll have deployment nightmares you didn't dream of and you'll be kicking yourself for not smoothing out the wrinkles. Do it early, and you'll thank yourself everyday for that small mercy...
Micro ORM Data Mapping with PetaPoco and ASP.NET MVC 4
Getting tired of working with the verbosity of Entity Framework classes and mapping? Well, you're not the only one, and in this quality post, Greg Arroyo takes us for a lap around the track using PetaPoco as your Micro ORM in MVC4.
Micro ORMs really are here to stay, and in some ways, more broadly applicable to web applications of today where everyone is trying to keep things more simple. If you haven't tried one yet, take this opportunity to get clued up on these fantastic tools.
ASP.NET MVC 4 Web API Routes and ApiController
Once again David Hayden masterfully takes us through a key piece of architecture that is going to be very important to anyone who will be working with MVC4. He details what seems to be a very slick piece of integration work between the new Web API framework and MVC4, and he throws in some OData queries for good measure.
It's short and sweet, and just enough to get you going, and whet your appetite for how to architect your solutions around your own APIs, allowing for more decoupled designs with less possible points of failure.
Getting started on your first Single Page Application
As with the introduction of any new method now encompassed in a technology, it's best to start with what comes straight from the horse's mouth. This Walkthrough put together by Brad Severtson gives you a great introduction, and leaves the mind boggling as to the possibilities.
If you've ever wanted to build your own Gmail and specifically wanted to do it with MVC, then go ahead, knock yourself out! (no pun intended)..
ASPHostCentral.com, the leader in ASP.NET and Windows Hosting Provider, proudly announces that we have supported the latest ASP.NET MVC 4.0 BETA Hosting.
To support Microsoft ASP.NET MVC 4.0 BETA Framework, we gladly inform you that we provide this beta account FREE of charge for a limited time (* terms and conditions apply).
New Features in ASP.NET MVC 4
This section describes features that have been introduced in the ASP.NET MVC 4:
- Enhancements to Default Project Templates
- Better Support for Mobile Project Template
- Enhancement in Display Modes
- Mobile Project Template support for VB.NET
- Dependency Injection Improvements
Terms and Conditions in Using this ASP.NET MVC 4.0 BETA Account
The followings are the features you will get under this FREE ASP.NET MVC 4.0 BETA Account:
- ASP.NET MVC 4.0 Beta Framework
- 1 Website/Domain
- 100 MB disk space
- 100 MB bandwidth
- 50 MB SQL 2008 space
- 24/7 FTP access
- Windows Server 2008 Platform
If you want to participate in this BETA program, there are several rules you need to understand:
- As this is a beta version, not all the features are available. They may be some issues on this beta framework, which will be fixed upon the full release of ASP.NET MVC 4.0 Framework
- ASPHostCentral.com does not guarantee the uptime of the sandbox solution. Additionally, we do not keep/store any backup of your files/accounts
- ASPHostCentral.com does not guarantee rapid response to any inquiries raised by a user
- This free account is only meant for testing. Users should not use it to store a production, personal, e-commerce or any blog-related site
- This free account is used to host any ASP.NET MVC 4.0 beta website only. Any questions that are not related to ASP.NET MVC 4.0 BETA will not be responded. A user shall not host any non-ASP.NET MVC 4.0 site on this free account either
- ASPHostCentral.com reserves full rights to terminate this beta program at any time. We will provide a notification on our Help Desk System prior to the termination of this program
- ASPHostCentral.com reserves full rights to terminate a user account, in which we suspect that there is an abuse to our system
- Once this beta program is terminated, your account will be completely wiped/remove from our system.
- This offer expires on 31st May 2012
If you wish to participate in this FREE ASP.NET MVC 4.0 BETA Program, you must register via https://secure.asphostcentral.com/BetaOrder.aspx
ASPHostCentral.com, the leader in ASP.NET and Windows Hosting Provider, proudly announces that we will support ASP.NET 4.5 Hosting.
To support Microsoft ASP.NET 4.5 Beta Framework, we gladly inform you that we provide this beta account FREE of charge for a limited time (* terms and conditions apply).
The followings are the features you will get under this FREE ASP.NET 4.5 BETA Account:
- .NET 4.5 Beta Framework
- 1 Website/Domain
- 100 MB disk space
- 100 MB bandwidth
- 50 MB SQL 2008 space
- 24/7 FTP access
- Windows Server 2008 Platform
If you want to participate in this Beta program, there are several rules you need to understand:
- As this is a beta version, not all the features are available. They may be some issues on this beta framework, which will be fixed upon the full release of ASP.NET 4.5 Framework
- ASPHostCentral.com does not guarantee the uptime of the sandbox solution. Additionally, we do not keep/store any backup of your files/accounts
- ASPHostCentral.com does not guarantee rapid response to any inquiries raised by a user
- This free account is only meant for testing. Users should not use it to store a production, personal, e-commerce or any blog-related site
- This free account is used to host any ASP.NET 4.5 beta website only. Any questions that are not related to ASP.NET 4.5 beta will not be responded. A user shall not host any non-ASP.NET 4.5 site on this free account either
- ASPHostCentral.com reserves full rights to terminate this beta program at any time. We will provide a notification on our Help Desk System prior to the termination of this program
- ASPHostCentral.com reserves full rights to terminate a user account, in which we suspect that there is an abuse to our system
- Once this beta program is terminated, your account will be completely wiped/remove from our system.
- For details, please check http://www.asphostcentral.com/ASPNET-45-Beta-Hosting.aspx
- This offer expires on 31st May 2012
If you want to participate on this FREE ASP.NET 4.5 Beta Program, you must register via https://secure.asphostcentral.com/BetaOrder.aspx
One pain point that’s dogged WebForm developers for some time is the fact that there haven’t been any strongly typed data controls. Some of the data controls I’m speaking of include the Repeater, FormView and GridView controls. They all used templates, which could allow you to specify a view for different operations, such as when you’re editing data compared to adding new data.
When you use these templates today, they’re using late bound expressions to bind the data. If you’re using the GridView control, or any of the other data controls, you’ll be familiar with the Bind or Eval syntax:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City">
<ItemTemplate>
<asp:Label ID="lblCity" runat="server" Text='<%# Bind("Address.City") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
One of the problems with late-bound data controls is you’re using a string to represent a property name. If you make a mistake typing the name, you won’t see the exception until runtime. It’s much better to catch these errors at compile time. Thankfully Microsoft has addressed this in ASP.NET 4.5 by implementing strongly typed data controls.
Installation
Before starting any development, you’ll need to install ASP.NET 4.5. The simplest way to do this is via the Web Platform Installer. All of the ASP.NET 4.5 articles I’m authoring are developed in Visual Studio 2011 Developer Preview. Here’s the link to get started.
Strongly Typed Data Controls
ASP.NET 4.5 introduces strongly typed data controls in the templates. A new ModelType property has been added to the data controls, and this allows you to specify the type of object that is bound to the control.
Setting this property will add that type to the data controls Intellisense (an autocomplete function), which means no more typing mistakes! This removes the need to run the website to see if you’ve made any typing mistakes during development.
In this example, I’ve connected to a Northwind web service. Using ASP.NET 4.5, I can set the ModelType to Northwind. If the requirement is for one-way data binding, you can use the Item expression. Bind("Name") becomes Item.Name. The same goes for the City property. Replace Bind("Address.City") with Item.Address.City.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" ModelType="WebApplication2.NorthwindService.Supplier">
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Item.Name %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City">
<ItemTemplate>
<asp:Label ID="lblCity" runat="server" Text='<%# Item.Address.City %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
For two-way data binding, use Binditem. So using the example above, data binding to a text box would be like this:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" ModelType="WebApplication2.NorthwindService.Supplier">
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:TextBox ID="txtName" runat="server" Text='<%# Binditem.Name %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City">
<ItemTemplate>
<asp:TextBox ID="txtCity" runat="server" Text='<%# Binditem.Address.City %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Intellisense is available, so there’ll be no more mistyped properties you only find out about at runtime.
Model Binding
Model binding focuses on coded data access logic. Previously if you wanted to display data in the GridView control, you either had to explicitly set the DataSource property and call its DataBind method from the code behind. Like this example:
protected void Page_Load(object sender, EventArgs e)
{
var products = GetProducts();
GridView1.DataSource = products;
GridView1.DataBind();
}
Alternatively you could use one of the many data source controls to bind the data to the GridView. Now that model binding is part of ASP.NET, you can explicitly tell the GridView which method to call to retrieve its data by using the SelectMethod property. Here’s the updated GridView.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" ModelType="WebApplication2.NorthwindService.Supplier"
SelectMethod="GetProducts">
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Item.Name %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City">
<ItemTemplate>
<asp:Label ID="lblCity" runat="server" Text='<%# Item.Address.City %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And in the code behind, here’s the GetProducts method:
public IQueryable<NorthwindService.Supplier> GetProducts()
{
var service = new NorthwindService.DemoService(new Uri(@"http://services.odata.org/OData/OData.svc/"));
var suppliers = (from p in service.Suppliers
select p);
return suppliers;
}
This method doesn’t need to be in the code behind. It could live in another class or assembly. The benefit of returning IQueryable is that it enables deferred execution on the query, and allows a data-bound control to further modify the query before executing it. This is useful when you need to implement sorting and paging methods.
I’m excited by the model binding and strongly bound data controls in ASP.NET 4.5. It has certainly borrowed these ideas and concepts from MVC, so fingers crossed more of them are implemented in upcoming versions