in

Chennai .Net User Group

A platform that enables you to Learn, Share & Grow (India's first .Net user group)

Shiju Varghese's Blog

October 2010 - Posts

  • Visual Studio Async CTP

    Microsoft has announced the Community Technology Preview (CTP) version of Visual Studio Async.The new Visual Studio Async CTP provides a new syntax for asynchronous development using C# and VB.NET. You can download the Visual Studio Async CTP from here.

    For more details visit the following link

  • My NoSQL Session at Microsoft Community Tech Day

    I did a presentation titled “NoSQL databases in .NET Apps” at  Microsoft Community Tech Day, Kochi  organized by Kerala Microsoft User Group. The session was an introductory talk on NoSQL databases and demonstrated how to use NoSQL databases in .NET applications. I have given a demo on NoSQL approach using RavenDB and ASP.NET MVC. The slide for the demo available at http://www.slideshare.net/shijucv/nosql-database-in-net-apps and the source code is available from http://ravenmvc.codeplex.com

  • Book Review : Test-Drive ASP.NET MVC

    image

     

    I just finished reading of Pragmatic Bookshelf's Test-Drive ASP.NET MVC written by Jonathan McCracken. This book gives an excellent introduction to ASP.NET MVC 2 using Test Driven Development (TDD) approach.  Jonathan introduces the ASP.NET MVC framework with a Test First development approach that gives you a better understanding of both ASP.NET MVC 2 and TDD. Jonathan's writing style is very enjoyable and can be easy to follow the whole book. He is explaining all concepts with good sample code. The book explores the topics such as IoC with Castle Windsor, NHibernate, Fluent NHibernate , Nunit, Rhino Mocks,  jQuery, REST and Build/Deploy that can be very useful for building real world ASP.NET MVC applications.


    This is a near 300 page book and it is not a reference for ASP.NET MVC but it will give you a better understanding of ASP.NET MVC with a practical and TDD way.  This book along with Steven Sanderson’s Pro ASP.NET MVC 2 Framework would be a great combination for learning and developing applications with ASP.NET MVC 2. I hope that this book won’t be the last book from Jonathan McCracken and expecting more practical books from him in future.

    I highly recommend Test-Drive ASP.NET MVC for those new to ASP.NET MVC Framework or Test Driven Development (TDD). This book will give you a better understanding of ASP.NET MVC Framework with a practical and TDD way.

    The contents of the book is given below

    1 Getting Started with ASP.NET MVC

    1.1 How ASP.NET MVC Works

    1.2 Installing MVC

    1.3 MVC in Five Minutes: Building Quote-O-Matic

    2 Test-Driven Development

    2.1 TDD Explained

    2.2 Test-Driving “Hello World”

    II Building an Application

    3 Getting Organized with MVC

    3.1 Time Management with GetOrganized

    3.2 Reading Data

    3.3 Creating a To-Do

    3.4 Deleting: Creating an Action Without a View

    3.5 Updating: Marking a To-Do as Complete

    4 Working with Controllers

    4.1 Creating Topics

    4.2 Using the FormCollection and TempData Objects

    4.3 Adding a Little Color with jQuery

    4.4 Controllers Talking to Controllers

    5 Managing State and Files with Controllers

    5.1 Enabling Filters and Results with Controllers

    5.2 Logging In

    5.3 Storing Information in Memory

    5.4 Manipulating Files

    5.5 Testing Routes in MVC

    6 Enhancing Views with HTML Helpers and Master Pages

    6.1 Making Our Site Presentable with HTML Helpers

    6.2 Building a Custom HTML Helper

    6.3 Simplifying Page Layouts with Master Pages

    6.4 Adding Validations Using ModelStateDictionary

    6.5 Replacing Web Controls with Advanced HTML Helpers

    7 Composing Views with Ajax and Partials

    7.1 Working with Ajax

    7.2 Finding It in a Snap with Autocomplete

    7.3 Using Partials to Reduce Duplication

    III Integrating with Other Frameworks

    8 Persisting Your Models

    8.1 MVC’s Next Top Model: NHibernate

    8.2 Using the Repository Pattern

    8.3 Mapping with Fluent NHibernate

    8.4 Creating and Reading Records

    8.5 Editing Models

    8.6 Deleting Records

    8.7 Additional ORM Data Relationships

    9 Integrating Repositories with Controllers

    9.1 Fixing the NHibernate Session Inside MVC . . . . . . .

    9.2 Using Inversion of Control with the IControllerFactory

    9.3 Injecting Repositories into Controllers

    9.4 Creating a Custom Action Filter

    9.5 Linking NHibernate and MVC Validations

    9.6 Preventing Performance Problems with Profiling

    10 Building RESTful Web Services

    10.1 Use SOAP or Take a REST Instead?

    10.2 Creating a Web Service

    10.3 Publishing to Blogger

    IV Security and Deployment

    11 Security, Error Handling, and Logging

    11.1 Applying Additional Security

    11.2 Using an Action Filter to Handle Errors

    11.3 Using Logging to See What Went Wrong

    11.4 Checking for a Pulse with ASP.NET Health Monitoring

    12 Build and Deployment

    12.1 Automating Builds

    12.2 Using MSBuild to Automate the Build

    12.3 Deploying to Production

  • Using the WebGrid Helper in ASP.NET MVC 3 Beta

    ASP.NET MVC 3 Beta is now supports to using ASP.NET Web Pages helpers in the Razor views. In post, let us discuss on how to use WebGrid helper in our Razor view page of an ASP.NET MVC 3 application.

    Let us create a view page using Razor syntax

    1. @model List<Employee>
    2. @{
    3.     View.Title = "Employee List";
    4. }
    5. @{        
    6.    
    7.    var grid = new WebGrid(source: Model,
    8.                 defaultSort: "FirstName",
    9.                 rowsPerPage: 3);
    10. }
    11. <p>
    12. <h2>Employee List</h2>
    13. <div id="grid">
    14.     @grid.GetHtml(
    15.         tableStyle: "grid",
    16.         headerStyle: "head",
    17.         alternatingRowStyle: "alt",
    18.         columns: grid.Columns(
    19.             grid.Column("FirstName"),
    20.             grid.Column("LastName"),
    21.             grid.Column("Salary",format:@<text>$@item.Salary</text>)
    22.         )
    23.     )
    24. </div>
    25. </p>

     

    In the above code, we create an instance of WebGrid with data source as our Model object and we specified that default sort is FirstName for the sorting purpose and rowsPerPage specified for the paging functionality. The GetHtml method of the WebGrid object will renders an HTML table for the grid helper. Using the the grid.Columns, we can specify which columns to display and we can also apply formatting for the columns.

    1. grid.Column("Salary",format:@<text>$@item.Salary</text>)

     

    The above code is applying a sign ($) before the column value Salary.

     

    The below code block is showing our Model class and the Action method

    Employee Class

    1. public class Employee
    2.     {
    3.         public string FirstName { get; set; }
    4.         public string LastName { get; set; }
    5.         public double Salary { get; set; }      
    6.         public static List<Employee> GetList()
    7.         {
    8.           List<Employee> employees = new List<Employee>{
    9.           new Employee   { FirstName="Rahul", LastName="Kumar", Salary=45000},
    10.           new Employee   { FirstName="Jose", LastName="Mathews", Salary=25000},
    11.           new Employee   { FirstName="Ajith", LastName="Kumar", Salary=25000},
    12.           new Employee   { FirstName="Scott", LastName="Allen", Salary=35000},
    13.             new Employee   { FirstName="Abhishek", LastName="Nair", Salary=125000}
    14.             };
    15.             return employees;
    16.         }
    17.     }

     

    Action Method

    1. public ActionResult Index()
    2.         {
    3.             var empoyees = Employee.GetList();
    4.             return View(empoyees);
    5.         }

     

    The screen shot of the view page is shown in the below. The data is displayed with paging and sorting functionality.

  • ASP.NET MVC 3 Beta Support for Code Runs before Views and Strongly Typed Models in Razor Views

    Code that Runs Before Views Run

    In ASP.NET MVC 3 Beta, we can add a file named _viewstart.cshtml in the views directory  and this will be shared among the all views with in the Views directory. The below code in the _viewstart.cshtml, sets the Layout page for every Views in the Views folder

     

    1. @{
    2.     Layout = "~/Views/Shared/_Layout.cshtml";
    3. }

     

    You can put a _viewstart.cshtml file on the any subfolders of Views folder and it will be shared only for that sub folder.

     

    Specify Strongly Typed Models in Razor Views

    In ASP.NET MVC 3 Beta, we can simply specify the strongly typed model using the following syntax

    1. @model Models.RegisterModel

     

    In the above syntax, we have specified RegisterModel in the Models namespace as strongly typed model for our Razor View.

  • ASP.NET MVC 3 Beta Released

    The ASP.NET team has released beta version of ASP.NET MVC 3. You can download the ASP.NET MVC 3 Preview 1 from here. You can read more details from ScottGu's blog post. You can download the ASP.NET MVC 3 Beta from here . Please keep in mind that you needs to install ASPNET Web Pages 1.0 in order to install ASP.NET MVC 3 Beta.

    The below are the summary of the new features of ASP.NET MVC Beta 3

    • NuPack Package Manager
    • Improved New Project Dialog Box
    • Simplified Way to Specify Strongly Typed Models in Razor Views
    • Support for New ASP.NET Web Pages Helper Methods
    • Additional Dependency Injection Support
    • New Support for Unobtrusive jQuery-Based Ajax
    • New Support for Unobtrusive jQuery Validation
    • New Application-Wide Flags for Client Validation and Unobtrusive JavaScript
    • New Support for Code that Runs Before Views Run
    • New Support for the VBHTML Razor Syntax
    • More Granular Control over ValidateInputAttribute
Copyright © 2002-2008 Chennai .Net User Group. All Rights Reserved. Microsoft and Microsoft logo's are trademarks of Microsoft Corporation