Creating URL’s in Mono Rail

Posted on Март 6, 2008. Filed under: .net, Castle project, Monorail, asp, coding |

They got a very simple URLHelper for Castle Project, it is used like:

$UrlHelper.For("%{action='YourAction'}")

And it DOES NOT take additional parameters, like some «id» or sth in a form, that would not make you specify all special symbols, ‘=’, ‘?’ and ‘&’ .. I should mention lack of up-to-date documentation. After googling for some time I realized, it would be better to write my own one. (I hope, I did not reinvent the will) I called it MyUrlHelper, extending it from AbstractHelper. To use it with NVelocity, supply it with action (yes, it does not takes controller as a parameter now) and a dictionary as the second parameter:

$MyUrlHelper.For("YourAction", "%{id=$item.id}")

and it will output a correctly formed URL. Place it in «Helpers» directory under your VS project and name it MyUrlHelper (by default). Then in corresponding controller, the one that passes data to your views, write something like this:

[Helper(typeof(YourProjectNamespace.Helpers.MyUrlHelper))]
public class YourController : BaseController
{
}

and it’s gonna work. Be sure, you explicilty mention MyUrlHelper in HelperAttribute attached to the controller, otherwise it won’t work!
It can be used without any restrictions, download it from depositfiles.com

UPD: Well, it seems, I reinvented the will ;) I had I version of MonoRail v 1 RC3, that had non-virtual methods of UrlHelper, but accordingly to this forum thread http://forum.castleproject.org/viewtopic.php?p=11283 they made them virtual on about Dec 27, 2007.

Make a Comment

Make a Comment: ( None so far )

blockquote and a tags work here.

    About

    кое что может быть интересно вам

    RSS

    Subscribe Via RSS

    • Subscribe with Bloglines
    • Add your feed to Newsburst from CNET News.com
    • Subscribe in Google Reader
    • Add to My Yahoo!
    • Subscribe in NewsGator Online
    • Последние комментарии ко всем записям в RSS
    • Subscribe in Rojo

    Meta

Liked it here?
Why not try sites on the blogroll...