ASP.NET MVC Preview 5 is the release I have been waiting for from Microsoft. The MVC team finally added easy model validation to the framework. The new features are detailed at Scott Guthrie’s blog. Validation was an issue that had previously hung me up when I dabbled with the MVC framework. Model validation enables another business rules validation in a way that I thought was very elegant. You can use partial classes to add business rules to a model class. This allows your business rules to be separate from the model classes and if you regenerate your model classes you won’t overwrite your business rules. I really like to see this because it means in my test project I can remove a layer of abstraction and keep the business rules close to the model classes.
I do have an issue with one of the new features in Preview 5 though and that is the [ActionName("action")] attribute. In conjunction with the [AcceptVerbs("POST")] attribute it allows you have different functionality for a URL depending on how its requested. This is necessary functionality I just have issue with the way its implemented. I would prefer to see something along the lines of this.
public object Create(string productName, Decimal unitPrice)
{
if (Request.Verb == "GET")
{
return View("Create");
}
else if (Request.Verb == "POST")
{
// save the data RedirectToAction("List");
}
}
I think this would make more sense. You wouldn’t have the possibility of confusion as to what action to call your code. You would always call the Create action. If you started getting actions with a lot of lines of code in them you could just refactor the code in the if else statements into new methods.
Posted on September 5th, 2008 by Matthew | No Comments »
I did something dumb and lost my WordPress theme. All hail the mighty Google though for helping track down the name of the theme I was using. I searched for a word in the title of one my recent blog posts and then clicked on the Google cache version of it and found the name of the theme I was using at the bottom of the page. I still lost all the changes to the theme I had made but at least I have somewhere to start from.
Posted on September 2nd, 2008 by Matthew | No Comments »
I was delving into ASP.NET MVC Preview 4 for a small project and I got hung up on form validation. Currently ASP.NET MVC provides no way to validate form input against the model objects. Form validation has to be written client side in JavaScript and server side in the action. I would really like to be able to decorate the LINQ-to-SQL objects fields with validation information like Rails does. I also hope they add some validator helpers to the the HTML helpers.
I see that someone else ran into this and went ahead and coded a solution for it the Forms Framework with Validation for ASP.NET MVC. This is an interesting approach to the problem I am not sure how it would deal with forms that are using more than one model. I want Microsoft to address this feature rather than cobbling basic functionality together from a lot of little side projects that may not see any further progress after their initial development.
Posted on August 13th, 2008 by Matthew | 2 Comments »
My last post was the result of making a beginners mistake and spending a lot of time being unable to resolve the issue. Since I am using IIS 6 on XP/2003 I have to add .mvc to my controller paths to activate the ASP.NET MVC framework on a URL. I was doing this and my controllers were working except for the / path of the web site.
ASP.NET MVC still needs a default.aspx in the root of the web site. The default.aspx just performs a redirect to the URL of whatever controller you are using for the site root. I had not changed the URL that default.aspx was redirecting to. Once I changed the URL the redirect was using my problem was fixed. I want to give a shout out to the official ASP.NET MVC forum for the help I got there. Its nice to see that a Microsoft product is building an actual community around this technology as that more than anything will help it grow and evolve.
Posted on July 24th, 2008 by Matthew | No Comments »
I tried to start a new project using the latest ASP.NET MVC framework update and it didn’t go so well. I ran into three issues that caused me to go back to the standard ASP.NET stack.
I was trying to redirect from an action on one controller to an action on another controller. RedirectToRoute wasn’t working for me instead of being redirected the current action just kept being reloaded. This really irritated me because either this is a bug in the framework or I was being tripped up by a misunderstanding of how asp.net mvc works.
When I went to the official asp.net mvc forum to see if I could find any documentation on this I found several people complaining about things that worked in preview release 3 that don’t work in release 4. This tells me the framework fundamentals are more in flux than I would feel comfortable dealing with at this time.
In trying to dig up documentation on the asp.net mvc framework there was no central repository of information. I really wish they would centralize the existing documentation and update it with each release.
Posted on July 23rd, 2008 by Matthew | 1 Comment »
I really hate to praise Microsoft but I have to say they have really made a few excellent products lately. First, I really like Windows Live Writer its not perfect but its way more enjoyable to use than any web interface for posting to a blog. I have investigated many weblog engines and played with the web forms they use for posting new content and I much prefer a desktop application for performing that task. I really wish there was a weblog editor for the Mac that was as good as Windows Live Writer.
Posted on June 27th, 2008 by Matthew | No Comments »
Newsgator toolbar is finally working for me in Firefox 3. I had some weird errors previously where the Newsgator toolbar wasn’t working for me in Firefox 3. I am really glad to have my subscribe in Newsgator button working again.
Posted on June 27th, 2008 by Matthew | No Comments »