Thursday, May 21, 2009

New Features of .NET 4.0

Microsoft recently released Visual Studio 2010 and .NET 4.0 beta.  I'd like to highlight some of the key new features available to .NET 4.0.

Web Forms

  • Developers can manage control IDs that affect rendered client ID
  • Remove ID bloat, and 'mangling'
  • CSS:
    • Ideally remove the need to use CSS adapters
    • Defer to CSS styles and bypass existing style properties
      • non-inline style attributes
    • Support non-table-based HTML rendering
  • URL-routing for web forms
    • Friendly url handling for web forms
    • configuration model for url routing
  • View state
    • Disable on the page, enable on specific controls - they will provide granular control of viewstate - today it is backwards
    • Disable on control, enable on child controls
    • GridView/ListView work better without viewstate
  • ASP.NET dynamic-data

Ajax

  • Continue ASP.NET Ajax innovation : RIA
  • Appeal to JavaScript Developers
  • Provide support for the page developer
  • jQuery including Intellisense
  • Templates and data binding
    • Client side handling, REST or Web Services
    • Covers page developer and component developer scenarios
  • DOM manipulation, selectors ...
  • Ajax higher-level components
    • Ajax Control Toolkit is a part of the strategy - they will make the toolkit part of the overall ASP.NET package
    • New controls
  • Centralized script libraries and break-up for performance

ASP.NET MVC

  • Appeal to those wanting separation of concerns, TDD, full control
  • Ruby on Rails, Django, PHP
  • Building on from ASP.NET MVC 1.0
  • ASP.NET MVC (Model View Controller)
  • Asynchronous controllers
  • Sub-controllers & Views
  • Declarative controls

ASP.NET Dynamic Data

  • Making building data-driven web apps easily
  • Attacking the Ruby on Rails crowd
  • Building on from FX3.5 SP1
  • Dynamic-data and MVC
    • Scaffolding, templates and data validation
  • Support for abstract data layer
    • Removes need for specific DL (SQL, entities ...)
    • Allows scaffolding of objects
  • Support for many to many relationships
  • Dynamic data on MVC -- this is on codeplex today
  • Built around something called field templates
  • Enhanced filtering:
    • Auto-complete, search filters

ASP.NET Core

  • Address customer pain points
  • Improve scale and performance
  • Cache extensibility and performance:
    • Enable caching like Velocity

There's a couple of videos on Mircosoft's Channel 9 that talk specifically about the points mentioned above:

Thursday, January 29, 2009

Building a jQuery-Powered Tag-Cloud with an ASP.NET MVC backend

NETTUTS had a great tutorial by Dan Wellman called "Building a jQuery-Powered Tag-Cloud" The problem for me was that the tutorial showed you how to connect to the database and pull tags and frequencies via PHP.

Because I am currently learning ASP.NET MVC I thought I would try to duplicate the results of the tutorial but with using ASP.NET MVC RC instread of PHP.  Here is how I did it.

I started by creating a Home Controller class.

HomeController.cs

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Web;
   5:  using System.Web.Mvc;
   6:  using System.Web.Mvc.Ajax;
   7:   
   8:  namespace MvcApplication5.Controllers
   9:  {
  10:      public class HomeController : Controller
  11:      {
  12:          //
  13:          // GET: /Home/
  14:          public ActionResult TagCloud()
  15:          {
  16:              return View();
  17:          }
  18:   
  19:          public JsonResult JSON()
  20:          {
  21:              List<object> tagcloud = new List<object>
  22:              {
  23:                      new { tag = "jQuery", freq = "10" },
  24:                      new { tag = "asp.net", freq = "3"},
  25:                      new { tag = "programming", freq = "183"},
  26:                      new { tag = "code", freq = "34" },
  27:                      new { tag = "HTML", freq = "58"},
  28:                      new { tag = "javascript", freq = "23"},
  29:                      new { tag = "people", freq = "43" },
  30:                      new { tag = "Google", freq = "3"},
  31:                      new { tag = "Microsoft", freq = "1"},
  32:                      new { tag = "Apple", freq = "10" },
  33:                      new { tag = "iPhone", freq = "38"},
  34:                      new { tag = "MVC", freq = "1"}
  35:              };
  36:              return Json(tagcloud); 
  37:          }
  38:   
  39:      }
  40:  }

What's happening here is that we are making a action for the View we will create and I am calling it TagCloud.  This action isn't going to provide us any data so it's a stub action.  The next Action we create is to provide TagCloud the JSON data.  In here I am creating a static List to send back serialized as JSON.  You could also tie it to a model and use Linq to SQL to build the List.

Our URL for the .getJSON method will be: /Home/JSON

This will return JSON data that looks like this:



Notice the difference in the JSON I am bringing back and the one Dan was bringing back.  I don't have a tags: with the rest of the data nested under it.  We'll need to update a line in the jQuery to make this work now.

Let's create the View for TagCloud.


TagCloud.aspx

   1:  <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
   2:   
   3:      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">  
   4:      <html>  
   5:        <head>  
   6:          <link rel="stylesheet" type="text/css" href="/content/tagcloud.css" />  
   7:          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
   8:          <title>jQuery Tag Cloud</title>  
   9:        </head>  
  10:       <body>  
  11:         <div id="tagCloud">  
  12:           <h2>Tag Cloud</h2>  
  13:         </div>  
  14:         <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>  
  15:         <script type="text/javascript">
  16:             $(function() {
  17:                 //get tag feed  
  18:                 $.getJSON("/Home/JSON",null, function(data) {
  19:                     //create list for tag links  
  20:                     $("<ul>").attr("id", "tagList").appendTo("#tagCloud");
  21:   
  22:                     //create tags  
  23:                     $.each(data, function(i, val) {
  24:   
  25:                         //create item  
  26:                         var li = $("<li>");
  27:   
  28:                         //create link  
  29:                         $("<a>").text(val.tag).attr({ title: "See all pages tagged with " + val.tag, href: "http://localhost/tags/" + val.tag + ".html" }).appendTo(li);
  30:   
  31:                         //add to list
  32:                         li.appendTo("#tagList");
  33:                         //set tag size  
  34:                         li.children().css("fontSize", (val.freq / 10 < 1) ? val.freq / 10 + 1 + "em" : (val.freq / 10 > 2) ? "2em" : val.freq / 10 + "em");  
  35:            
  36:                     });
  37:                 });
  38:             });  
  39:         </script>  
  40:       </body>  
  41:    </html>  

As we start to loop through the JSON data Dan was telling jQuery to start inside tags with data.tags, since we don't have tags we can just use the variable data like so: $.each(data, function(i, val) {

The rest of setting this up is the same as NETTUTS article.  All that remains is the css.




Download the Source

jQuery-TagCloud_source.zip (44.82 KB)



Wednesday, January 28, 2009

ASP.NET MVC Release Candidate - No Codebehinds on Views

Check out Scott Guthrie's mammoth blog post on what's changed in this release of the ASP.NET MVC RC that was pushed to the public today.  A lot has changed in my opinion.  One change that I wasn't expecting was that Views and View User Controls do not have code-behinds any more.

The problem was the only way to have strongly typed Views was to inherit in the code behind.  This caused an issue with intellisense in the aspx/ascx pages. You would need to create and immediately build in order to have intellisense work.

No one was using the code-behinds anyways.  The code should be in the Controllers.

Here is the write up from Scotts Blog:

Views without Code-Behind Files

Based on feedback we’ve changed view-templates to not have a code-behind file by default.  This change helps reinforce the purpose of views in a MVC application (which are intended to be purely about rendering and to not contain any non-rendering related code), and for most people eliminates unused files in the project.

The RC build now adds C# and VB syntax support for inheriting view templates from base classes that use generics.  For example, below we are using this with the Edit.aspx view template – whose “inherits” attribute derives from the ViewPage<Product> type:

One nice benefit of not using a code-behind file is that you'll now get immediate intellisense within view template files when you add them to the project.  With previous builds you had to do a build/compile immediately after creating a view in order to get code intellisense within it.  The RC makes the workflow of adding and immediately editing a view compile-free and much more seamless.

Important: If you are upgrading a ASP.NET MVC project that was created with an earlier build make sure to follow the steps in the release notes – the web.config file under the \Views directory needs to be updated with some settings in order for the above generics based syntax to work.

Monday, January 26, 2009

BarCamp Rochester 4

BarCamp Rochester 4 has been announced for April 18th at RIT.  I missed last years and wish I could of attended.  This year I kicked myself in the butt and signed up to present on ASP.NET MVC.  This will force me to do a couple of things.  It'll force me to really understand MVC and it'll force me to be prepared.

Now if it'll force me to rewrite my blog in ASP.NET MVC by then who knows. Would be a good talking point.

Anyway, here is an initial structure of my presentation I am thinking about:

  • Introduction
  • MVC
    • Current uses (ruby on rails, CakePHP, etc.)
    • MVC in the wild (StackOverflow)
    • Status of MVC
  • MVC vs Web Forms
  • Demo (perhaps build a simple blog)
Any suggestions?

Blog Posts by:

The Official jQuery Podcast

with Ralph Whitbeck & Rey Bango

You can subscribe to the show in iTunes or via the raw RSS feed

My Twitter Updates

View Twitter Page