Los Techies : Blogs about software and anything tech!

Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label


In part two of this series I will cover the different components of the Input as it is rendered to HTML and explain how each of those are created by the Input Builder.

Given the following form layout I will explain each feature of the input builder framework.

image_thumb2

the Label

inputbuilder-label

The text highlighted in red are labels that come from the Model type. The label is created from the PropertyInfo object that represents the respective properties of the mode.

  1. The label is Property Name.
  2. The label is the Property Name that is split on the pascal case property name.
  3. The label is specified by using the Label Attribute applied to the property.

inputbuilder-label-model

The html for the label is created in a Content control of the Field.Master Master Page. That control is highlighted in red.

inputbuilder-label-masterpage

That explains how the labels are rendered to the html for the builder.  There will be more posts in this series to explain the other conventions followed by the Input Builders.

 

This is part 2 in the series.

Kick It on DotNetKicks.com
Posted Jun 09 2009, 09:26 PM by erichexter
Filed under: , , , ,

Comments

Jeffrey Palermo (.com) wrote Input Builders for ASP.NET MVC in the works
on 06-09-2009 11:20 PM

Subscribe to my feed here: feeds.jeffreypalermo.com/jeffreypalermo Eric Hexter has started a multi - part series on Opinionated Input Builders .  They are expression-based, meaning they eliminate the need for most strings for Html Helpers

Erik wrote re: Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label
on 06-10-2009 12:00 AM

Interesting stuff. If I'm following you correctly, there's one instance of this field.master for each input control?

Keep it coming - I'm going to be embarking on a very large MVC project soon and I like what I'm seeing here. =)

erichexter wrote re: Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label
on 06-10-2009 12:10 AM

@Erik  There is one field.master that is master for all of the partials.. It controls the layout for the builders and is used to control the layout for the Inputs.

Erik wrote re: Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label
on 06-10-2009 12:23 AM

Ah, I see - cool. =) Can't wait to see more!

Reflective Perspective - Chris Alcock » The Morning Brew #365 wrote Reflective Perspective - Chris Alcock » The Morning Brew #365
on 06-10-2009 1:39 AM

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #365

Anders Juul wrote re: Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label
on 06-10-2009 1:43 AM

Hi Erich,

You (with the other contributors) are really filly filling out a gap in MVC - much appreciated! Looking forward to getting the source and get started with it!

Yours,

Anders, Denmark

Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout … wrote Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout …
on 06-10-2009 3:12 AM

Pingback from  Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout …

Kristoffer Ahl wrote re: Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label
on 06-10-2009 3:33 AM

I really like the simplicity of it. I can actually see the other devs on our team using this as they would not need to know anything about the markup. On the downside though I'm not a fan of putting view-related stuff on my model (even if it's a viewmodel). The reason why is that I know that the front end people wouldn't know how to find the model, change whatever is needed, compile and try it out. But I guess that I could go with .UsingPartial("SomePartial") instead.

I think the idea of using templates is a good one as it would be very easy to modify the form markup for all your views but I don't think it's very readable and I don't think I'll be able to pass it on to a designer to implement their markup in there.

Another thing I was thinking of is localization. What are your thoughts on that?

Nigel Sampson wrote re: Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label
on 06-10-2009 3:43 AM

It's looking very interesting, one thing though, there's quite a few attibutes in ComponentModel.DataAnnotations that you could use for consistency rather than your own. DisplayName instead of Label, UIHint instead of Partial.

One great thing for something like that means the annotations can be reused in other places. Such as a DynamicData back end or RIA Services.

Looking forward to seeing what comes around.

sarong wrote re: Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label
on 06-10-2009 6:47 AM

source code would make it possible to give some feedback

erichexter wrote re: Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label
on 06-10-2009 7:11 AM

@Nigel,  The attributes I am using here actually are DataAnnotations attributes. the PartialView inherts from the UIHint for example. I just wanted to provide a syntactically clean ...ie no training required way of applying the convention.  The patial view code does look for a UIHInt rather than a PartialView attribute.

@sarong  I will get the source zipped up and uploaded this morning.

Remco Ros wrote re: Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label
on 06-10-2009 7:44 AM

Looks nice,

looking forward to see some implementation details.

Eduardo Miranda wrote re: Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label
on 06-10-2009 9:53 AM

Hi Eric,

Cool stuff you are building.

One question: Do you have a solution for multi-language UIs? Using .NET resources maybe?

erichexter wrote re: Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label
on 06-10-2009 10:14 AM

@Eduardo,  the builders support my default convention.. but allow you do plugin your own convention.. The next post will show how to change the convention for the partial view selection but the approach is the same for each element.  As long as you can define a way to determine how to find your resource key from a PropertyInfo object representing each property than it is a pretty simple convention to implement.

DotNetShoutout wrote Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label - Eric Hexter -
on 06-10-2009 2:44 PM

Thank you for submitting this cool story - Trackback from DotNetShoutout

Duncan Godwin wrote re: Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label
on 06-10-2009 3:52 PM

Looking at this I'm now wondering about conventions that can just be applied globally as defaults rather than per property. e.g.

- Format all dates in this way, with this control and use this validator.  

- Any property called Html or Comment give a multi-line text field.  

- Setup convention validation for all e-mail addresses for properties that contain Email.  

- All fields called Name are required.  

Maybe I'm pushing it a little now :)

erichexter wrote re: Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label
on 06-10-2009 3:59 PM

@Duncan,, I think you are totally getting it.  If you look at the Part 4 there is a static func that is the extensibility point to each of these properties.  That is where you could implement _your_ conventions.  I guess I have spent more time explaining how to configure the exceptions rather than explaining the Convention based approach..... Which is actually the most powerful part of this.

Daily Links for Wednesday, June 10th, 2009 wrote Daily Links for Wednesday, June 10th, 2009
on 06-10-2009 10:05 PM

Pingback from  Daily Links for Wednesday, June 10th, 2009

Eric Hexter wrote Opinionated Input Builders for ASP.Net MVC – Part 4 the Partial View Inputs
on 06-10-2009 11:02 PM

Part 1 – Overview Part 2 – the Labe l Part 3 – the Source Code Part 4 – the Partial View Part 5 – the

Opinionated Input Builders for ASP.Net MVC ??? Part 3 the source code. - Eric Hexter - wrote Opinionated Input Builders for ASP.Net MVC ??? Part 3 the source code. - Eric Hexter -
on 06-10-2009 11:05 PM

Pingback from  Opinionated Input Builders for ASP.Net MVC ??? Part 3 the source code. - Eric Hexter -

Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label - Eric Hexter - wrote Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label - Eric Hexter -
on 06-10-2009 11:06 PM

Pingback from  Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label - Eric Hexter -

Jeffrey Palermo (.com) wrote Input Builders for ASP.NET MVC series continues from Eric Hexter
on 06-10-2009 11:48 PM

Eric Hexter is continuing his multi - part series on Opinionated Input Builders . He’s on a role! They are expression-based, meaning they eliminate the need for most strings for Html Helpers in your views. Part 1 – Overview Part 2 – the Labe l Part 3

Alexander Byndyu wrote re: Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label
on 06-11-2009 12:24 AM

Why SimpleModel object can know about self-validation? I think we need SimpleModelValidator and add IHasValidation to impleModel object.

Haacked wrote re: Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label
on 06-11-2009 12:35 AM

Eric, you should Html Encode the Model.Name and Model.Label in your <label for="..." /> snippet. :)

Opinionated Input Builders for ASP.Net MVC ??? Part 5 the Required input - Eric Hexter - wrote Opinionated Input Builders for ASP.Net MVC ??? Part 5 the Required input - Eric Hexter -
on 06-11-2009 6:53 AM

Pingback from  Opinionated Input Builders for ASP.Net MVC ??? Part 5 the Required input - Eric Hexter -

Daily Links for Thursday, June 11th, 2009 wrote Daily Links for Thursday, June 11th, 2009
on 06-11-2009 8:02 AM

Pingback from  Daily Links for Thursday, June 11th, 2009

erichexter wrote re: Opinionated Input Builders for ASP.Net MVC - Part 2 Html Layout for the Label
on 06-11-2009 9:10 AM

@Alexander,  the actual validation is a seperate concern which would probably be tied into your model binder.  But the portion of this framework in the convention could  implement your own convention which could query the model and determine things like required fields.  The actual Validation in the UI are helpers around displaying the messages that are stored in the model state the is already part of the MVC framework.  This just ties the layout of these together.

@Haacked, Busted... I will update my example and source.

Eric Hexter wrote Opinionated Input Builders Part 6 – Performance of the builders
on 06-13-2009 1:15 PM

Part 1 – Overview Part 2 – the Labe l Part 3 – the Source Code Part 4 – the Partial View Part 5 – the

Eric Hexter wrote Opinionated Input Builders - Part 7 More on Performance / Take 2.
on 06-14-2009 3:15 PM

Part 1 – Overview Part 2 – the Labe l Part 3 – the Source Code Part 4 – the Partial View Part 5 – the

ASP.NET MVC Archived Blog Posts, Page 1 wrote ASP.NET MVC Archived Blog Posts, Page 1
on 06-14-2009 11:02 PM

Pingback from  ASP.NET MVC Archived Blog Posts, Page 1

Eric Hexter wrote Opinionated Input Builders – Part 8 the Auto Form
on 06-17-2009 1:47 PM

Part 1 – Overview Part 2 – the Labe l Part 3 – the Source Code Part 4 – the Partial View Part 5 – the

Eric Hexter wrote Opinionated Input Builders – Part 9 override the default Date Time picker
on 06-30-2009 9:07 AM

  Part 1 – Overview Part 2 – the Labe l Part 3 – the Source Code Part 4 – the Partial View Part

Summary 11.06.2009 – 02.07.2009 « Bogdan Brinzarea’s blog wrote Summary 11.06.2009 &ndash; 02.07.2009 &laquo; Bogdan Brinzarea&#8217;s blog
on 07-02-2009 8:16 AM

Pingback from  Summary 11.06.2009 – 02.07.2009 «  Bogdan Brinzarea’s blog

Opinionated Input Builders for ASP.Net MVC using partials ??? Part 1 - Eric Hexter - wrote Opinionated Input Builders for ASP.Net MVC using partials ??? Part 1 - Eric Hexter -
on 07-23-2009 2:00 AM

Pingback from  Opinionated Input Builders for ASP.Net MVC using partials ??? Part 1 - Eric Hexter -

Copyright Los Techies 2008, 2009. All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems