b# - Controller is NOT the New Code-Behind: ""
Ben has a great example of how things can get out of control even in a framework designed to simplify your code. I agree with his point and one of the MVC developers responds in his comments. So it looks like the issue will get taken care of quickly, if it hasn't been already.
I wanted to point out one bit that I saw that maybe needs re-factoring. It was in the original code and the re-factored portion that Ben posted.
-
if (Request.HttpMethod != "POST")
-
{
-
return View();
-
}
Now I'll speak from ignorance for a second since I haven't gotten to look at the MVC code since preview 2. (Just too busy, busy with a new job). It seems to me that these lines could pop up in a lot of places in your MVC application. It would be nice if we could mark certain methods as POST or GET only. Maybe when defining the route. There may be a way to do this already in the routing system.









3 Comments
Scott,
In preview 4 there is a RequireHttpMethodAttribute in Microsoft.Web.Mvc.dll that removes the need for this code.
++Alan
Actually Scott, the reason they have that in there is so that the can dual purpose the action.
MVCContrib has an attribute called [PostOnly] which you’d use on things like:
//usercontroller
[PostOnly]
public ActionResult Delete(int id)
{
….
}
to prevent someone from navigating to that url.
This attribute is now replaced by the frameworks [RequireHttpMethod("POST")] attribute.
The example you show allows them to have a single action, and if you POST to it you get different results. I don’t think I like it very much, but it’s a pattern I’ve seen a few places.
It still seems like there are two separate operations going on here, one with a POST context, and one with a GET context. Maybe two separate controller methods are needed?
But I see what they are doing there with the attribute.
One Trackback/Pingback
[...] to VoteASP.NET MVC re-factoring (7/30/2008)Wednesday, July 30, 2008 from http://www.lazycoder.comI agree with his point and one of the MVC developers [...]
Post a Comment