Url.Action not able to match a route

in my Mvc controller I have the following action with a defined route

 [HttpGet]
    [Route("OrderLineSchedule/{salesOrderId}/{webOrderId}/{orderLineNumber}")]
    public async Task<ActionResult> OrderLineSchedule(string salesOrderId, int? webOrderId, int orderLineNumber)
    { 
//code 
    }

In one view I have the following link trying to cree the url using with Html.Action helper method.

 <a href='@Url.Action("OrderLineSchedule", "Orders", new { area = "account", SalesOrderId = Model.SalesOrderId, WebOrderId = Model.WebOrderId, OrderLineNumber = Model.OrderLineNumber})' id="lnkOrderLineSchedule">@Model.Quantity @Model.ActivityName</a>

The problem is - only in one occasion when Model.SalesOrderId property is null - in this case Url.Action is not able to construct any url pointing to this action. I will appreciate any hep

1 answer

  • answered 2022-05-07 06:52 thisisnabi

    Make sure MapMvcAttruteRoute before MapRoute in RegisterRoutes. and your Controller names should be OrdersController

    MapMvcAttruteRoute - Location

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum