how to make working my query

Hi, i got 2 link on created with  

<a href="@Url.RouteUrl("

and the other with

 <li>@Html.RouteLink(

both give me the right routed link :

first link

http://localhost:57959/Magazine/Index/1/styles-inspirations

second link

http://localhost:57959/Magazine/Index/1/styles-inspirations/2/fetes-occasions

but only the second works with the query, why?

if (menuid.HasValue)
             {
               magazines = magazines.Where(r => r.ParentMenuMag.MenuId.Equals(menuid.Value));
            }

            if (submenuid.HasValue)
            {
                magazines = magazines.Where(r => r.ParentSubMenuMag.SubMenuId.Equals(submenuid.Value));
            }

how to make working the first link with my search?

Hi graphic,

Thanks for your post.

grafic.web

<a href="@Url.RouteUrl("

You can use it directly,like this:

    @Url.RouteUrl(...);

More information:

http://www.patridgedev.com/2011/08/22/subtleties-with-using-url-routeurl-to-get-fully-qualified-urls/

Hope it can be helpful.

Best Regards,

Eileen

grafic.web

<a href="@Url.RouteUrl("

@Html.RouteUrl returns a url string and it does not render anchor tag

grafic.web

<li>@Html.RouteLink(

@Html.RouteLink renders a anchor tag with url

Hi,

how should i modify my code of the query to make working this with <a href="@Url.RouteUrl(" ?

if (menuid.HasValue)
             {
               magazines = magazines.Where(r => r.ParentMenuMag.MenuId.Equals(menuid.Value));
            }

with this :

<li>@Html.RouteLink(

my second query works well :


            if (submenuid.HasValue)
            {
                magazines = magazines.Where(r => r.ParentSubMenuMag.SubMenuId.Equals(submenuid.Value));
            }

In fact  the problem is that with <li>@Html.RouteLink( the query above works and not wiht
<a href="@Url.RouteUrl("

How to modifiy this query?

post your routelink and routeurl completely to know how u used

Hi,

here my RouteConfig.cs :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace HairCollection3
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}/{title}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, title = UrlParameter.Optional }
            );

            //localhost/Magazine/menuid/menuname/submenuid/submenuname/ID
            routes.MapRoute(
            name: "MagazineRoute",
            url: "{controller}/{action}/{menuid}/{menuname}/{submenuid}/{submenuname}/{id}",
            defaults: new { controller = "Magazine", action = "Index", menuid = UrlParameter.Optional, menuname = UrlParameter.Optional, submenuid = UrlParameter.Optional, submenuname = UrlParameter.Optional, id = UrlParameter.Optional }
           );


        }
    }
}

And the link

first link (SEARCH QUERY does not work)

<a href="@Url.RouteUrl("MagazineRoute", new { controller = "Magazine", menuid = menu.MenuId, menuname = MenuName.URLFriendly() })" title="@MenuName">@MenuName<i class="fa fa-angle-down"></i></a>   

second link (SEARCH QUERY works wel)l :

<li>@Html.RouteLink(SubMenuName, "MagazineRoute", new { controller = "Magazine", menuid = menu.MenuId, menuname = MenuName.URLFriendly(), submenuid = submenu.SubMenuId, submenuname = SubMenuName.URLFriendly(), })</li>

This is the SEARCH QUERY

if (menuid.HasValue) // First link
             {
               magazines = magazines.Where(r => r.ParentMenuMag.MenuId.Equals(menuid.Value));
            }

            if (submenuid.HasValue)  //second link
            {
                magazines = magazines.Where(r => r.ParentSubMenuMag.SubMenuId.Equals(submenuid.Value));
            }

grafic.web

<a href="@Url.RouteUrl("MagazineRoute", new { controller = "Magazine", menuid = menu.MenuId, menuname = MenuName.URLFriendly() })" title="@MenuName">@MenuName<i class="fa fa-angle-down"></i></a>

I do not find any issue with the above

is the link only for GET or also for POST

Hi, me too, but i don’t know why it does not work with this query :

if (menuid.HasValue)
             {
               magazines = magazines.Where(r => r.ParentMenuMag.MenuId.Equals(menuid.Value));
            }

And the second link, works well with the other query, in fact if i click on it i see only the list of the
ParentSubMenuMag.SubMenuId.Equals(submenuid.Value

How should i change this query to work with this link?

<div>

The problem is that if i change my link :

<a href="@Url.RouteUrl("MagazineRoute", new { controller = "Magazine", menuid = menu.MenuId, menuname = MenuName.URLFriendly() })" title="@MenuName">@MenuName<i class="fa fa-angle-down"></i></a>    

like this :

@Html.RouteLink(MenuName, "MagazineRoute", new { controller = "Magazine", menuid = menu.MenuId, menuname = MenuName.URLFriendly() })</li>

it works perfectly… so the problem, i guess is in the  @Url.RouteUrl(", becaus if i use the
@Html.RouteLink( the query can find the menuid.HasValue

How comes?

</div>

Leave a Reply