Specifying CSS classes and html attributes with MVC helpers

 

Ok you’ve finally got you MVC controller and models all wired up, you BL is fine, now you want to pretty up those views, so you’ll start to use some css and javascript.


Here’s how you can specify html attributes with your html helpers.

Button sample:

image

 

Form sample:

image

Note @ is used to escape the c# keyword class.

image

Progressive Enhancement with Modernizr

 

If you’ve been to a HTML5 session or lived in the html5 world for any length of time you’ll have come across the term “Progressive Enhancement”. It’s about taking a base application that works on downstream browsers and detecting features and increasing functionality if you have certain features.

Take example local or session storage, in older versions of browsers there was no local storage so there would be more round tripping.

So how do we detect these features? One method is a javascript file called Modernizr that detects feature availability (rather than using a database etc).

Syntax:

   1:  if (Modernizr.localstorage) 
   2:  {    
   3:      // browser supports local storage
   4:  }
   5:  else 
   6:  {    
   7:      // browser doesn't support local storage
   8:  }
   9:   

 Check out modernizer it's got many detection and abstracts you from detection techniques.

You’ll get this script added to your project for free in MVC3.

Ain’t she sweet

 

Nothing, really ground breaking, but don’t it look neat! (if i say so myself). (that facebook link will be going up alongside flicker/twitter when i get around to it.).

Site written in asp mvc3/ jQuery / razor / graphics in photoshop and content owned by the thecamerafly.
Another few hours will have the initial prototype ready to go live, hopefully this w/end as I’m in the land of Java workwise for the next two days at least and that will probably eat into my evenings.

image

Next on my little personal agenda is to create an online expense tracking system, with automatic historic currency conversions, if anyone want’s to lend a hand on this let me know, I’ve one or two ideas on where to get currency rates Smile given permission Smile, also I’m thinking at looking at the OSS option given enough interest.

Charts in MVC3

 

So you want to draw a chart in MVC and don’t know where to start?

Step 1) Create a new MVC3 project

Step 2) Open NuGet and add a library reference to “microsoft-web-helpers”

image

 

image

Step 3) Change your action method to create a new chart and write it to the response stream

 

image

 

Result)

image

Step Additional )

You could return a partial view and even call it from Ajax if you wanted, you could just return Json and use a client side vector graphics library.
Or you would create your own html helpers / function to make life easier. (many ways to skin a cat).