MVC vs MonoRail – Action Methods
July 31st, 2009 . by Daniel HölblingMany people have said nasty things about the Castle MonoRail framework since ASP.NET MVC has come out. Both serve the same purpose but both frameworks are pretty different. I did/do projects in both these days, and usually all features of A are also present in B, just slightly different.
One thing where this isn’t true is the layout of ActionMethods in MVC:
In short, MonoRail can have unlimited method overloads for ActionMethods while MVC can only overload twice (once for each HttpVerb).
What do I mean?
MVC:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(int id)
{
return View();
}
}
MonoRail:
public class ContactController : SmartDispatcherController
{
public void Index()
{
}
public void Index(int id)
{
}
public void Index(int id, string name)
{
}
}
You can see clearly, MonoRail as a framework is much smarter about what action method it will invoke. Based on what parameters you supply it will pick the best match.
MVC will simply use reflection to invoke any method with that name that matches the HttpVerb, so once you remove the AcceptVerbs attribute MVC will break with a AmbiguousMatchException.
MVC vs MonoRail
Just to get bias out of the way: I believe MVC is technically still inferior to MonoRail but makes that up in larger community and (much) better documentation. What you pick is largely dependant on how well you know your way around missing documentation and open source code mailing lists.
To illustrate this I went to stackoverflow and compared the number of questions tagged with asp.net-mvc with those tagged castle-monorail. The results may very well speak for themselves:
It’s a shame I have to say. MonoRail is such a nice framework and it really does not deserve getting stomped by ASP.NET MVC. As funny as this may sound for a OSS project, currently the best way to contribute to MonoRail is to write about it and if possible improve documentation around it. I guess that says everything about the quality/maturity of the framework.



[...] is much smarter about action methods than MVC so there are already things going on with default values through routing etc. But this [...]
Really though, your graph on monorail vs microsoft potentially says that monorail is BETTER than asp.net mvc, right? A framework that’s so good, no questions even need to be asked??
I don’t think you can say that.
MonoRail’s documentation is rather lacking and there are many questions that have to be asked before you know everything.
The graph just illustrates how much more traction ASP.NET MVC has in the community than MonoRail.
It’s like with most things MS does. They come years late to the party, but once they decide it’s going to be their way they get behind it with all their enourmous manpower and surpass them.
greetings Daniel
Heh.
Hammet suggested that we do the same heuristic based overload resolution like Monorail does but we decided against it for now. We wanted to do the simplest thing that works. It keeps the code simpler and the behavior easier to understand, in my opinion. For example, you might add a new hidden input to the form for some reason and suddenly a form submission is calling another action method you didn’t expect.
However, I’m always open to suggestions for improvement. You’ve described a neat feature, but you haven’t sold me on why it’s important or necessary.
After all, you can pretty much get the same result with:
public ActionResult Index(int? id, string name)
{
return View();
}
Also, you were innacurate about MVC. You can have more than two overloads. After all, there are more than 2 HTTP Verbs, right?
If you only use AcceptVerbsAttribute, you can have an action method per HTTP verb. There are four standard verbs, but many more than that.
Also, AcceptVerbsAttribute derives from ActionMethodSelectorAttribute. You could write your own attribute that derives from ActionMethodSelectorAttribute and implement any number of overloads of an action method, as long as one action method is selected for a given request.
Hi Phil,
I agree with you, although I doubt that anybody is using more than 2 HttpVerbs on a standard Data input form.
While reading through the MVC source (literally 30 seconds ago) I found out that the Exception only occurs if > 1 method remains after filtering.
I’ll update the post tomorrow (it’s 0:00 in Austria)
Now, for why I wrote this post in the first place:
I wanted to have a page that lists all users of a site, and the ability to search for names:
public ActionResult List();
public ActionResult List(string query);
Since the first would just invoke GetAll() and the latter a query with a Like clause, I’d like to have those in two different methods instead of one with a if statement when using nullable types.
Anyway, thanks for your comment.