Los Techies : Blogs about software and anything tech!

Opinionated Input Builders for ASP.Net MVC – Part 4 the Partial View Inputs


This is the forth part of the series. 

Given this form that is generated by the input builders the partials for each data type of the Model are selected by the builder based on a simple convention.

 image

Each partial control is selected using the following convention:

  1. The type of the property is used to find a Partial View by the same name.
  2. If the partial does not exist in the /Views/Shared/ directory it is pulled from an embedded resource from the Input Builder assembly.  This allows you to override the conventions of the framework with your own.
  3. If a PartialView Attribute is applied to a property it is used to override the previous conventions.
  4. Display a partial using a Chained Method on the Input() method UsingPartial( partialName )

Looking at the types of the model you can see that the Enum partial will render a Select element by default.  The PartialView(“RadioButtons”) attribute was applied to override the default and have the build render the RadioButtons.aspx partial view.

image

 

This is an example of using the Chained Method override instead of using an attribute based approach.

image

This convention of utilizing the partial views allows the separation of concerns (SoC) of the markup from the conventions which determine which partial to render.

What if you do not like the convention ?????   Each part of the UI model is extensible.  There are two conventions that are at play here.  The selection of the partial view and the selection of the data that is used by the controls to display the possible selections.  This is shown for the enum data types which allows the select and radio button inputs to display a list of possible values. 

 

The ModelPropertyFactory class calls two methods to execute the conventions.  The ParialNameConvention and ModelPropertyBuilder by using the static Func fields this will allow your project to define your own conventions if you do not like mine.  This is an important extensibility point that gives the great flexibility to this approach.  There are conventions like this for each of the elements used within the partials. 

image

Kick It on DotNetKicks.com
Posted Jun 10 2009, 11:00 AM by erichexter

Comments

Mihai wrote re: Opinionated Input Builders for ASP.Net MVC – Part 4 the Partial View Inputs
on 06-10-2009 12:19 PM

This is better ;) way better thanks for the change in specifying the partial to be used

ASP.NET MVC Archived Buzz, Page 1 wrote ASP.NET MVC Archived Buzz, Page 1
on 06-10-2009 12:26 PM

Pingback from  ASP.NET MVC Archived Buzz, Page 1

erichexter wrote re: Opinionated Input Builders for ASP.Net MVC – Part 4 the Partial View Inputs
on 06-10-2009 12:43 PM

@Mihai I had the support in there, I just struggle with how to explain the various way to put all of this together.  I could see this same model apply to all of the attributes..  but the converse is that if you were to use say a validation framework that was attribute based and you already specified a Required attribute than I would like to just reuse that rather than specifying in the view that the property is required...  it is a tough balance to deal with.

LaptopHeaven wrote re: Opinionated Input Builders for ASP.Net MVC – Part 4 the Partial View Inputs
on 06-10-2009 1:26 PM

BY adding another InputBuilder HiddleField.aspx, which uses the HiddenField.Master master page, you could then call

<%=Html.Input(c => c.UserID).UsingPartial("HiddenField")%>

If you wanted to show non-guid values (ints) in a hidden field.

mendicant wrote re: Opinionated Input Builders for ASP.Net MVC – Part 4 the Partial View Inputs
on 06-10-2009 2:08 PM

I really like how it looks so far. I guess the only thing that bothers me is that maybe you'd want to use a strongly typed enum like InputBuilderPartial.RadioButtons and InputBuilderPartial.DatePicker instead of just "RadioButtons" and such.

I can see a lot of interesting things coming from this though.

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

Thank you for submitting this cool story - Trackback from DotNetShoutout

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

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

Pingback from  Opinionated Input Builders for ASP.Net MVC ??? Part 4 the Partial View Inputs - Eric Hexter -

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

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 4 the Partial View Inputs
on 06-11-2009 9:14 AM

@mendicant the problem with using enums is that there would be some basic partials that are provided as part of this project but most project would add additional partials... say a set that do a lot of ajax stuff. AutoCompletes, Date or Time Pickers... So the problem with enums is that the framework does not allow enums to be inherited. So I think you could implement an enum that is project specific to eliminate the strings.. I could add that to my sample project.

Reski wrote re: Opinionated Input Builders for ASP.Net MVC – Part 4 the Partial View Inputs
on 06-11-2009 5:26 PM

Is it posibble to adding Hidden method within IInputSpecification interface, so we can easily hide value instead of create new partial view ?

erichexter wrote re: Opinionated Input Builders for ASP.Net MVC – Part 4 the Partial View Inputs
on 06-11-2009 8:34 PM

Oh well under the hood the hidden method would delegate to a partial view.  But that is what I am using for the Guid.aspx partial view now.  It makes me think that rather than having the partial views named after the data types that they should be named after the ui controls. Than the convention would do the translation between the type to control to render it.  I think this would really come up for integers. I could see them being used as hidden values slider controls and up down controls.

Bill Pierce wrote re: Opinionated Input Builders for ASP.Net MVC – Part 4 the Partial View Inputs
on 06-12-2009 6:14 PM

How would you accomplish the requirement of selecting radio button "One" should update the list of availble items in drop down list x?

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

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

cristian wrote re: Opinionated Input Builders for ASP.Net MVC – Part 4 the Partial View Inputs
on 06-22-2009 7:38 PM

Interesting the use of the partial renderer, I've been using it to render relation between properties, your implementation is wonderful.

What if I need to display a dropdown box from, let's say it, a repository? for example, the School property from Student needs to display a drop down list of schools taken from the SchoolRepository?

erichexter wrote re: Opinionated Input Builders for ASP.Net MVC – Part 4 the Partial View Inputs
on 06-23-2009 10:27 PM

@Christian, you would implement your own DefaultConventions.ModelPropertyBuilder. In order to create values for your drop down you would add your own way to pull values based on the School PropertyType.

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:17 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 -

CodeJunkies wrote Building a forum application, Part 7
on 02-26-2010 4:29 AM

Building a forum application, Part 7

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