$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.
Комментариев нет:
Отправить комментарий