the UrlHelper will be able to generate urls if you have a matching
rule for it.
$Url.For("%{controller='product', action='view',
params={name='ProductName'}}") would generate a URL if you have a
valid route, I guess like this:
RoutingModuleEx.Engine.Add(
new PatternRoute("/<controller>/<name>")
.DefaultForAction().Is("view"));
You can add restrictions for it if you like.
This would make:
/product/ProductName
call ProductController, on action View(string name) where name =
'ProductName'.
You would need to internally map 'ProductName' to the approriate id in
your action aswell as use the correct ProductName in your UrlHelper in
the view.
I would however combine productname with the id instead, like this:
/product/15/product-name
so that I would get 15 in my view, without the need for any mapping.
This however needs another route than the one I supplied.
Hope this helps.
On 10 feb 2009, at 22:22, eyal wrote:
>
> Hi All,
>
> I am interested in re-writing some of my urls to make them url
> friendly. I found this blog
> http://using.castleproject.org/display/MR/Routing+Overview
>
> My agenda is to convert the following:
> .../controllerName/searchresult.ashx?categoryId=23
>
> into
>
> .../controllerName/categoryName
>
> where each categoryId is associated with a Category Name
>
> Also I am not sure how to associate the two following code snippets
> found on blog:
> Code:
>
> RoutingModuleEx.Engine.Add(
> new PatternRoute("/<controller>/<name>/<id>/view.aspx")
> .DefaultForAction().Is("view")
> .Restrict("id").ValidInteger
> );
>
>
> I found that just by using the $UrlLink(... on my view I can re-write
> a url. But the url is not initially generated into the browser's url
> address. Instead it appears as a hyper link on the page. Once clicked
> only then it will re-write the url address in the browser - that is
> useless to me. What am I missing here?
>
> Code:
>
> $Url.Link('Product Name', "%{controller='product', action='view',
> params={id=15, name='ProductName'}}")
>
>
> Thanks
>
> Eyal
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---