eWorld.UI - Matt Hawley

Ramblings of Matt

ASP.NET MVC - ActionResult... The Good & Not So Bad

April 18, 2008 18:21 by matthaw

I'm thoroughly enjoying the new ActionResult feature the ASP.NET team introduced into the "refresh" of the Preview 2 bits... or whatever they're calling it now :) Introducing this has increased productivity regarding testing the results of a controller's action. Here's a quick summary of the different types:

  • RenderViewResult - this result is returned when you call RenderView on the controller. It has properties like ViewName, MasterName, ViewEngine, ViewData, and TempData.
  • ActionRedirectResult - this result is returned when you call RedirectToAction on the controller. It exposes a dictionary of information.
  • HttpRedirectResult - this result is returned when you call Redirect. It exposes the Url that it is to redirect to.
  • EmptyResult - This is used for any other purpose in which you don't want the controller to complete the execution on. I have already used this for outputting HTML to the response stream for a specific purpose.

Now that these action results are present, there's no need to have your own view engine that captures the same information. What else is great, is that you can implement your own action result to do whatever you wish!

Onto the Not so Bad

1. When calling RenderView with the parameterless method, this renders testability useless because the RenderViewResult that is returned has Null values where you'd expect to find a value. For example, the critical property "ViewName" is null.

2. I feel that ActionRedirectResult should expose a ViewName and ViewData property. As it stands, when you call RedirectToAction, it takes your view name you've specified and puts it within the RouteValueDictionary it exposes. While this is still testable - it would be much easier to test if I could just go off of ViewName and ViewData.

All in all, this is a very good start to using ActionResults, and I love using them. Hope my insight helps!

kick it on DotNetKicks.com



New Drop of ASP.NET MVC

April 16, 2008 19:27 by matthaw

There's a new drop of ASP.NET MVC out on CodePlex now. Once again, there's some breaking changes, but nothing too terribly bad this time. Notably

  1. Action methods now return an ActionResult.
  2. It contains the changes to routing that Phil Haack mentioned.

Also, they've included all of the test cases too, so now you can be assured they are following good practices! Check out the Read Me for the latest changes in this drop.



Less Ramp-Up Time with Pair Programming?

April 15, 2008 00:50 by matthaw

Being my first day on the CodePlex team, I figured it'd be filled with "read this", "watch that", and "understand da code". Being that any other job I've started in the past has a significant ramp-up time, I would have guessed CodePlex would be no different. While I think there will be some time before I'm fully comfortable, I'd say that coming on board the first day and already writing some code is a success! Thanks pair programming!



New Beta of Website Live

April 13, 2008 01:23 by matthaw

Beta ScreenshotJust wanted to share the beta of my re-designed website. Please kick the tires some for me and give me some honest criticism. The first thing you'll notice is the ditching of the yellow & blue with a more fun green & orange.

You'll also notice that I did a bit of re-organization within the menu, but for the most common tasks - I added a "quicklinks" section that hopefully has the most common tasks one is looking for. I've also tied my blog in with the new design, displaying the last 10 entries, hoping to drive more visitors to the site.

Again, please enjoy this and comment on what you like, don't like, whatever!

Linky to Beta



MVC UI Validation Framework

April 2, 2008 16:36 by matthaw

The last few days I've been working on a MVC UI validation framework that closely follows that of ASP.NET. While my implementation is only in it's baby steps, I decided I would post it to the MVC Contrib project, and follow as much standards as what they have. Overall, the framework is very simple and straight forward in it's use.

Here were my requirements:

  1. It must closely match the ASP.NET UI validation framework.
  2. It should support all of the ASP.NET validators in their minimalistic implementation.
  3. It should require very minimal script inclusion or code to make this happen.
  4. It should only by a client side framework as you should be protecting your data on the server side through normal validations.

What I came up with, includes:

  1. It utilizes the ASP.NET UI validation framework by leveraging the WebUIValidation.js file (emitted through WebResource.axd).
  2. It supports all of the validators, with extended support for validation groups:
    1. RequiredValidator
    2. RegularExpressionValidator
    3. RangeValidator (currently does not support Date or Currency data types)
    4. CompareValidator
    5. CustomValidator
  3. It exposes 2 script inclusion calls, and 1 form validation setup call
    1. ValidatorRegistrationScripts() - Will render the WebUIValidation.js script, and scripts for form validation upon submission. This should be placed within the head tag.
    2. ValidatorInitializationScripts() - Will render all of the "expando" attributes for all validators upon the page and any initialization calls to set things up. This should be placed at the very end of your page before the closing body tag.
    3. FormValidation() - Will return an IDictionary object containing the "onsubmit" attribute. This should be called when creating your <form> tag.
  4. It is only a client-side framework leveraging ASP.NET's WebUIValidation.js

Since you now have an idea of the requirements and what was met, here's an example of it in action:

   1:  <%@ Import Namespace="MvcContrib.UI.Html" %>
   2:  <html>
   3:     <head>
   4:        <%= Html.Form().ValidatorRegistrationScripts() %>
   5:     </head>
   6:     <body>
   7:        <% using(Html.Form<MyController>(c => c.Save(), FormMethod.Post, Html.Form().FormValidation())) { %>
   8:        First Name: <%= Html.TextBox("firstName") %>
   9:        <%= Html.Form().RequiredValidator("firstNameRequired", "firstName", "First Name is Required.") %>
  10:        <%= Html.Form().RegularExpressionValidator("firstNameRegex", "firstName", "[a-zA-Z]*", "First Name can only contain letters.") %>
  11:        <br />
  12:        Age: <%= Html.TextBox("age") %>
  13:        <%= Html.Form().RequiredValidator("ageRequired", "age", "Age is Required.") %>
  14:        <%= Html.Form().RegularExpressionValidator("ageRegex", "age", "[0-9]*", "Age can only be numeric.") %>
  15:        <%= Html.Form().RangeValidator("ageRange", "age", "18", "35", ValidationDataType.Integer, "Age is not in target range of 18-35.") %>
  16:        <br />
  17:        <%= Html.SubmitButton("submit", "Save") %>
  18:        <% } %>
  19:        <%= Html.Form().ValidatorInitializationScripts() %>
  20:     </body>
  21:  </html>

At this point, I've posted it as a patch to MVC Contrib project, and hoping they apply it Smile. If you would like to get your hands on it, check out the patches page, mine is #1063. Please let me know your input, I tried making it as simple as possible to use, and I believe I've achieved that.

Update: My patch has been applied by Eric :) Get the latest build (>= 0.0.1.96) it if you'd like to check this out. Also, let me know of any issues you may find by logging bugs on the CodePlex site.



Open Source Web Designs

March 30, 2008 15:36 by matthaw

When I was setting up my blog (I used BlogEngine.NET) I was walking through some tutorials on how I can create my own theme since none of the built-in ones fit my overall site style. One of the videos I was watching showed him converting a design from Open Source Web Design. This is a very cool site for the design challenged folks like me who can't come up with a good color combination or a great layout scheme.

Since viewing this site, I've decided it was time for me to ditch my current website look and bring in some new "flavor". Now, it's not live yet - but I'm still working on my redesign and will post when that is live. If you have any other cool open source sites like this or repositories for [free] stock images, please let me know. This stuff is great!



Windows Developer Power Tools

January 11, 2007 07:36 by matthaw

I've been keeping this under wraps for about 6 months now, but since the book has been finally published & I just received my copy, I'm happy to promote the book Windows Developer Power Tools.I was asked by James Avery and Jim Holmes to be a contributor writing about Unleash It. Check out the book as it has a ton of awesome free & open source tools, and read my section (12.8) starting on page 650. Yay!



EntLib 3.0 CTP

December 23, 2006 04:41 by matthaw

Ohh, just in time for the holidays, Enterprise Library 3.0 has just had it's first CTP released. Might have to give it a whirl to see what I can use from it versus the current 2.0 version I'm using. Some of the new features look interesting, especially the new Validation Application Block & Application Block Software Factory. Good thing I'm leaving my computer behind, otherwise I think my wife would divorce me. Check out the new site on CodePlex.



Categories: .NET | Development
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

FogBugz getting an API & VS2005 Plugin!

December 22, 2006 16:29 by matthaw

Yes, the title says it all. FogBugz is getting an exposed API (oddly enough feels like WebServices but isn't even close - rar!) in the next version. The good news is there's a beta version of this API already out that enables a new Visual Studio 2005 Plugin to see your cases by your various filters. I've been wanting something like this for home for quite awhile, so I'm quite happy to see this finally exists. I would have posted sooner about this, but it was a rocky start for the API as it's already on (my version #, not there's) 1.2 due to some bugs not allowing me or many others to work with it. So definately check this out if you're using FogBugz and Visual Studio 2005 & hate to have a separate IE window open to manage your bugs.



Released: Excentrics World Server Controls v2.0.4

November 18, 2006 22:12 by matthaw

Version 2.0.4 of Excentrics World Server Controls has just been released targeting just two annoyance bugs that were introduced with v2.0.3. The control set has also been compiled against Microsoft AJAX Extensions, Beta 2 to ensure continued full compatibility - however it'll still function just fine with Beta 1. The bugs that were fixed were:

  • Fixed issue where the *Image types for the CalendarPopup and TimePicker were not being rendered correctly to the client.
  • Fixed issue where the next month link or image was being displayed outside of the calendar.

The updated version can be downloaded by visiting http://www.eworldui.net/Download.aspx. The official build number for this release is 2.0.4.2327.





Copyright © 2000 - 2024 , Excentrics World