Search code examples
c#asp.net-mvcurl-routing

Is there a reason Url.Action("Grid", "List", new { id = "Organisation"}) would return /List/Index/Organisation instead of /List/Grid?id=Organisation


I'm using Razor in a view and need to generate a Url yet its returning /List/Grid/Organisation instead of /List/Grid?id=organisation

var id = Model.EntityName.ToLower();
Url.Action("Index", "List", new { id = id})

I'm expecting List/Index?id=organisation to be returned yet instead am getting List/Index/Organisation. I'm not sure if its a version issue or I am missing something as I'm fairly new to Razor/C#.

EDIT:

$.get('@Url.Action("Grid", "List", new { id = id})&key=@key&pageNumber=' 
+ pageNo + '&pageSize=' + pageSize 
+ '&searchName=@Model.UniqueID' 
+ query, function (data) 
{
 $("#@Model.UniqueID").tablegrid('loadData', data);
});

And the controller

public override JsonResult Grid(string id, string key, string searchName, string searchText, string activeTabs, string pages, string filters, string query, string orderBys, string options, string context, int pageSize = 10, int pageNumber = 1)
        {
            return base.Grid(id, key, searchName, searchText, activeTabs, pages, filters, query, orderBys, options, context, pageSize, pageNumber);
        }

It's part of a call used to retrieve information from the database and fills a grid. This code is used on other projects yet for some reason on this new project its giving issues


Solution

  •  routes.MapRoute(
                    name: "List",
                    url: "list/{id}/{action}",
                    defaults: new {controller = "List", action = "Index", id = UrlParameter.Optional}
                    );
    

    was meant to be

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

    Thanks to @mjwills who pointed me in the right direction.