The MVC framework: more on the MvcInputControl

Oh well…after all, the MvcInputControl is more complex than I initially thought. The problem was that I was using SVN for getting the code and it seems like the current available release is for that kind of access is still RC1. Fortunately, you can still download the source from codeplex and that is what I did. So, the current release (RC2) adds a property to the previous list: Format. As you can probably guess, you can use this property to specify the format that should be applied to the value that is rendered by the INPUT control.

Besides this property, the class adds further logic to the rendering method. In this version, the INPUT control’s value can come from several places, by this order:

  1. it tries to get an attempted value from the associated ModelState (it uses the Name property to try to get a valid ModelState entry). If it gets one, then it will simply set it as the value of the INPUT control and it won’t apply any kind of formatting to it (even if you set up a value to the Format property, it won’t be applied);
  2. It then tries to get a value from the attributes you’ve set up on the markup;
  3. If that doesn’t return a valid value, it will try to get that info from the view data dictionary.

If the it gets a value from 2 or 3 and the Format property was set up, it will apply that form to the string before adding it to the rendered attributes. Finally,it performs a final step: it checks for eventual errors on the associated ModelState (again,remember that it uses the Name property for getting that info from the view data dictionary). If it finds any, it will automatically add the default validation css class (HtmlHelper.ValidationInputCssClassName) to the control. And now I believe the MvcInputControl has been accurately described.

Keep tuned for more on the MVC framwork.

Advertisements

~ by Luis Abreu on March 11, 2009.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

 
%d bloggers like this: