views:

48

answers:

2

I have the following route ( it's the first in my global.asax )

    routes.MapRoute(
    "AdminCompany",                                              // Route name
    "{controller}.aspx/{action}/{companyId}/{id}",                           // URL with parameters
     new { controller = "Home", action = "Index", companyId = "", id = "" }  // Parameter defaults
    );

if i navigation to

"Order/DisplayAdmin/2/79000180" it resolves correctly

However if i do the following

Html.ActionLink("View", "DisplayAdmin", new {companyId = Model.CompanyId, id = order.OrderNumber }, new { @class = "button add" })

it displays

/Order.aspx/DisplayAdmin/39068760?companyId=0

which also works, but isn't so pretty :)

Here is my Controller Method

   public ActionResult DisplayAdmin(int companyId, [DefaultValue(0)]int id, [DefaultValue(0)] int orderItemStatusId)
        {
            var viewModel = DisplayAdminViewModel(companyId, id, _statusResponses);
            return View(viewModel);
        }

Am i calling ActionLink the wrong way? how do i get the nice Urls?

+1  A: 

only thing I can think of that is happening is that its falling back to the Default route, I did a copy paste of both your route and the html.ActionLink and it works perfectly for me displaying it like "/Order.aspx/DisplayAdmin/39068760/45456", i did replicate the same fault like you get if the naming isn't the same in the route and action link.

Joakim
Can you please expand on "the naming isn't the same in the route and action link."?
Ahmad
if the route parameters has a certain name, those exact names must be used in the actionlink for it to work properly. that was what I meant, I can see that it was unclear the way I said it.
Joakim
A: 

Use the overload of ActionLink that has a RouteValueDictionary argument.

It appears that you are currently using the overload with the "object" argument and it's going to a workable, but not as clean, url.

AndrewDotHay