Hi Jimmy,

Works great.

Also I noticed that images on searchresult page/s disappeared. I am
assuming that it has to do with the re-writing of the url. Any idea of
how to fix this?

this is how I pull the image to display on page:
            <img name="Image_$cnt" alt="$Html.HtmlEncode($row.Title)"
src="../container/images/product_images/thumb$image.FileId" border="0"/
>

Thanks
Eyal

On Feb 11, 1:26 am, Jimmy Shimizu <jimmy.shim...@gmail.com> wrote:
> you need to name the params in your route to the same thing as what you
> pass on to the UrlHelper, like this:
>
>  rules.Add(new PatternRoute("/<controller>/<name>/<productId>/
> <action>.ashx")
>
> I guess you need to skip the action aswell, since you define a default,
> that's not needed:
>
>  rules.Add(new PatternRoute("/<controller>/<name>/<productId>/")
>         .DefaultForAction().Is("searchresult")
>         .Restrict("productId").ValidInteger);
>
> eyal wrote:
> > Now I'm closer to a real solution
>
> > see changes:
>
> >>         public static void Register(IRoutingRuleContainer rules)
> >>         {
>
> >             rules.Add(new PatternRoute("/<controller>/<name>/<id>/
> > <action>.ashx")
> >               .DefaultForArea().IsEmpty
> >               .DefaultForAction().Is("searchresult")
> >               .Restrict("id").ValidInteger);
> >           }
>
> > in view
>
> >  #foreach($Product in $Products)
>
> >>    <li>$Url.Link($Product.Name, "%{controller='products',
> >> action='searchresult', 
> >> querystring='productId=$Product.Id,params={id=$Product.Id, 
> >> name=$Product.Name}}")</
> >> li>
> >> #end
>
> > The resulted url:
> > .../specials/myproduct/11/searchresult.ashx?productId=11
>
> > However I want the url to appear as such .../specials/myproduct/11/
>
> > How can I do this?
>
> > thanks
>
> > eyal
>
> > On Feb 10, 4:43 pm, eyal <ebarda...@gmail.com> wrote:
>
> >> I looked into your suggestions and that is what I decided to do:
> >> #foreach($Product in $Products)
> >>    <li>$Url.Link($Product.Name, "%{controller='products',
> >> action='searchresult', params={id=$Product.Id, name=$Product.Name}}")</
> >> li>
> >> #end
>
> >>         public static void Register(IRoutingRuleContainer rules)
> >>         {
> >>             rules.Add(new PatternRoute("/products/productId/
> >> searchresult.ashx")
> >>               .DefaultForArea().IsEmpty
> >>               .DefaultForAction().Is("searchresult"));
>
> >>         }
>
> >> When I click on the generated link I get the following error within
> >> the BaseHttpHandler.cs in func. Process(HttpContext context):
> >> " ex = {Unable to evaluate expression because the code is optimized or
> >> a native frame is on top of the call stack.}"
>
> >> Any idea why?
>
> >> thanks
>
> >> Eyal
>
> >> On Feb 10, 3:06 pm, Jimmy Shimizu <jimmy.shim...@gmail.com> wrote:
>
> >>> 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 
> >>>> bloghttp://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 castle-project-users@googlegroups.com
To unsubscribe from this group, send email to 
castle-project-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to