About your host

Photo of your host - Charles Vallance Charles Vallance is a web developer with a slight case of OCD when it comes to nice clean standards compliant html and code.

Badges

twitter / cvallance
My articles have been featured in The Morning Brew - Daily .NET News and Views

Tag Cloud

more tags...
July 2009 Entries

I currently have a situation where I have two separate actions that rendered the same view and then on this view it has two individual forms which post to the two aforementioned controller actions.

Each of the forms have their own separate ValidationSummary() calls to display their validation errors. But when I posted to either one of these actions and the validation failed, I quickly realised a short coming of the built in ValidationSummary() helper method… you see, it doesn’t have a clue about which form has the errors!

Confused yet? Oddly enough, so am I.

A screen shot should clear things up:

register-login

And the fail:

register-login-fail

Making sense now? Good...

Anyway, I came up with an easy enough work around so I thought I would share it.

namespace System.Web.Mvc
{
    public static class HtmlExtensions
    {
        public static string ActionValidationSummary(this HtmlHelper html, string action)
        {
            string currentAction = html.ViewContext.RouteData.Values["action"].ToString();
            
            if (currentAction.ToLower() == action.ToLower())
                return html.ValidationSummary();
            
            return string.Empty;
        }
    }
}

I'm (basically) calling it like so:

<h2>Register</h2>

<%= Html.ActionValidationSummary("Register") %>

<form method="post" id="register-form" action="<%= Html.AttributeEncode(Url.Action("Register")) %>">

... blah ...

</form>


<h2>User Login</h2>

<%= Html.ActionValidationSummary("LogIn") %>

<form method="post" id="login-form" action="<%= Html.AttributeEncode(Url.Action("LogIn")) %>">

... blah ...

</form>

And that's it. Enjoy.

Technorati Tags:

I’ve got myself a brand spanking new VPS. w00t!

So with some help of the ‘oh so clever’ infamous Claw @ Signify I’ve got my DNS server up & running and everything seems to be going just super*.

Along with the new VPS I’ve decided to upgrade my blog from Wordpress to Subtext. Which, surprisingly, wasn’t that easy consider Wordpress doesn’t natively export to BlogML (there really should be standard between all blog engines).

Anyway, I got an export working using the BlogML project on CodePlex along with some additional hacking of the resulting XML file. So all my previous, extremely out of date, posts are back if anyone is still using ASP.NET MVC CTP’s. Ha.

As for the new blog, after some rather exhausting searching for a decent skin for my new Subtext install, I couldn’t find anything that I really liked so I’ve decided to port the Lazy Days skin by Fullahead with inspiration from Steven Harman and his Subtext port. So far so good, but as you can tell I’ve got alot more to go!

More updates to come - to the skin and to my blog that is. I, hesitantly, promise to update more often than I have been (last update January 2008!). Focus will be on the best thing to come out of Microsoft in years – ASP.NET MVC.

*Yet to fully setup hMailServer – how hard can it be? ;-)

Technorati Tags: