Topic: ASP.NET MVC

Creating a Basic CRUD Application with Backbone.js Starter Kit

This is a first part of a multi-part series article where I will show you how to create a relatively simple CRUD Application with Backbone.js. The Application is a personal finance application where the user will be able to create multi-currency accounts and should be able to track expenses and incomes. The application is created with the Backbone.js Starter Kit of my previous post and the full source code is hosted on GitHub.

Introducing Backbone.js StarterKit

Recently I completed few Backbone.js Single Page Applications, one of the thing that really bored me was setting up the project. It seemed that I was doing the same stuff over and over again like setting up the folder structures, installing the required nuget packages, writing the same user registration and login codes etc. So I decided to create a project template which I can use as a starting point for my application and thus born the Backbone.js StarterKit and thankfully and it is now showcased in asp.net single page application section. It was initially created as a VSIX extension, I know unlike myself, people often do not like to install something new unless it is absolutely necessary, so I have also created separate nuget packages that includes all the features of the VSIX template, just create an empty ASP.NET MVC project and install your preferred package.  Although my preferred client side language is CoffeeScript but I encounter clients who prefers pure JavaScript as well as clients who become fan of typescript due to its auto complete and compilation support in VS.  So there are three separate nuget packages which are same but implemented in different languages. To Install the package, open the package console in VS and type your preferred version:

Html5 Offline Cache Integration with ASP.NET MVC Bundle

One of the lesser known and misunderstood feature of Html5 is offline cache, with carefully crafted it can make your application blazingly fast. In this post, I will show you how can you implement offline cache with the new asp.net asset bundle, the same technique can be also applied to other asset managers like combres or cassette. Currently the browser support of offline cache is aligned towards mobile platform comparing to desktop(except IE all other has this support) but the nice thing of offline cache is the browser that does not support it will simply ignore it, on the other hand the mobile platform which is dominated by the mobile web-kit has first class support of it, so I will use the default jQuery Mobile project the comes with the ASP.NET MVC 4.

The ASP.NET WebAPI and its shortcomings

I managed some time to stab the new ASP.NET WebAPI, I have developed few Http API in the past solely on ASP.NET MVC instead of going through the WCF route. My goal was to check how much work I can delegate it to the new WebAPI instead of doing it myself. No, I am not going to show you some CRUD controller that does the basic stuffs, I take it for granted. Instead, I would show you something that is more realistic. The example that I am going to present a Contact resource that has id, first name, last name and a collection of associated addressed, still pretty basic stuff.

Entity Framework Code First Bootstrapping

This post is primarily for my fellow friends of local .net user group who asked for a rough guideline on how to get started with the latest Entity Framework Code First, I will try to keep it short and concise. I assume that it is going to be used in an ASP.NET MVC Application and behind the scene an IoC container would be used to glue everything. Before going into the implementation details there are certain design choice of mine, first persistence ignorance which means the domain model have no clue whether Entity Framework is used or any other ORM (nothing fancy here, out of the box the EF Code First has this support), next, I prefer to use class mapping which I think gives a bit more control comparing to decorating the domain classes with the data annotation attributes. Lets starts with a typical Category, Product, Customer and Order domain.

ASP.NET MVC ViewModel usage and pick your best pattern

In this post, I will start with typical usage of view model in view that you often see in ASP.NET MVC Applications with full of tag soup, then I refactor it incrementally to correct the implementation and finally show you a better implementation which promotes better OOP and encapsulation, makes the view fully logic-less by delegating the presentation logic to a separate class. Lets see the initial implementation, consider a User Profile view which contains the following code:

ASP.NET MVC with PAjax or PushState/ReplaceState and Ajax

In the recent episode of RailsCasts (highly recommended even if you have tiny bit of interest in Rails) Ryan Bates shows a nice little but very elegant trick to load different pages with Ajax request. The fundamental difference of this trick with the vanilla jQuery.ajax is that it keeps the browser history intact, the visitor of the page will see the regular url change in the browser location bar and it would even degrade gracefully if the browser JavaScript is turned off. Behind the scene it uses a jQuery plugin called pajax which does the heavy lifting, by default the plug-in comes with a Sinatra example, there is also a Rails integration gem which is written by the DHH(creator of Rails) himself. In this post I will use the same Sinatra example but ported to ASP.NET MVC.

Meet Spine.js – My framework of choice for client side MVC (Part 2)

In the last post, we have used Html5 local storage for persistence, in this post we are going to integrate it with ASP.NET MVC. Before moving forward, let me tell you that frameworks like backbone.js and spine.js expects your server endpoints are RESTful and do utilize the http verbs, for example the same endpoint can perform different things based upon the http verb. Unlike Rails, the default Controller and routes that ASP.NET MVC generates does not have those features. So we need to tweak the ASP.NET MVC to improve its “RESTful-ness”. In case, if you are wondering about the url structures, here is the list of defaults of ASP.NET MVC:

ASP.NET MVC 4 Developer Preview and My Feedback

Okay so a new preview version is now available and according to the release notes the major features that it includes is the better view selection (aka mobile template), new default project template and Task based Async Controller and few other minor things. Since this is a developer preview, quite a few things can be changed before the rc/rtm, so I think it the best time to give your feedback. Lets run down each of the item, shall we?

Meet Spine.js – My framework of choice for client side MVC (Part 1)

Take a cup of coffee or light up your smoke, this is going to be a lengthy post, I know this is long due to some of my friends over twitter and reading after Rob Conery’s “The BackboneJS and Knockout DanceOff” I decided to start writing it finally. This post will cover a basic introduction of Spine.js, the things you have to do to integrate it with ASP.NET MVC and finally why Spine.js is my framework of choice when there are other popular alternatives for the client side development.

I will be writing all of my client side codes in CoffeeScript, if you are new to CoffeeScript then do visit CoffeeScript official site (the previous link) and there are also few more free resource like little book of CoffeeScript, Smooth CoffeeScript or blog post series of Jan Van Ryswyck which you can check. In order to compile your CoffeeScript to JavaScript inside Visual Studio you can use the new tool Web Workbench from the good guys of Mindscape or the popular open source add-in Chirpy. You can of course use the plain old JavaScript but after writing CoffeeScripts in last four months I can only say I am not going back to the plain JavaScript unless the languages features that exists in CoffeeScript are introduced in JavaScript. In short, CoffeeScript is a tiny little language which brings most of the good stuffs from Ruby, Python and probably from Perl to write highly readable and beautiful codes that compiles down to JavaScript.