Html Conventions in MVC

Just today, Jimmy wrote a great post on using HTML conventions in MVC using FubuMvc’s core HTML conventions. Go ahead a read it. I’ll wait here.

The problem with this is that it heavily relies on StructureMap (FWIW I love SM, but its overkill here), and doesn’t quite fit into the way MVC does things. It also requires a lot of setup. I found this out almost 2 years ago now, and so SchoStack.Web was born. Over the coming posts I will go through what’s included in the library, but here is how you quickly get up and running with the default conventions (these represent the defaults that render lists, dropdowns, checkbox’s which are all MVC compliant).

  1. Create new mvc project.
  2. install-package schostack.web
  3. Replace System.Web.Html namespaces in Views/web.config with the following
    <add namespace=”SchoStack.Web.Html” />
    <add namespace=”SchoStack.Web.Html.Form” />
  4. In Application_Start add:
    HtmlConventionFactory.Add(new DefaultHtmlConventions());
    HtmlConventionFactory.Add(new DataAnnotationHtmlConventions());
    HtmlConventionFactory.Add(new DataAnnotationValidationHtmlConventions());
  5. Thats it.

The following are the three main helpers used to generate all HTML based on your conventions.


All the usual MVC helpers are available as well like ValidationSummary and ValidationMessage.

I’ll try to cover the following things in upcoming posts, but if you have any questions or issues you can ask/raise them on github.

1. Creating your own conventions
2. Closer look at out of the box conventions
3. Validation (Server and Client validation using either FluentValidation and Data Annotations driven off the input model, not the viewmodel)
4. Foreach Loop Helpers
5. Url Generation and Routing


This entry was posted in .NET and tagged , , , . Bookmark the permalink.

2 Responses to Html Conventions in MVC

  1. Paul Van Gundy says:

    Just noticed your github link is broken.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s