Creating URL’s in Mono Rail

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

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

Добавить комментарий

Заполните поля или щелкните по значку, чтобы оставить свой комментарий:

Логотип WordPress.com

Для комментария используется ваша учётная запись WordPress.com. Выход / Изменить )

Фотография Twitter

Для комментария используется ваша учётная запись Twitter. Выход / Изменить )

Фотография Facebook

Для комментария используется ваша учётная запись Facebook. Выход / Изменить )

Google+ photo

Для комментария используется ваша учётная запись Google+. Выход / Изменить )

Connecting to %s

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

%d такие блоггеры, как: