Why is the value of the Optional parameter automatically populated by routingata in MVC5?

I have an MVC action similar to this in a controller called ReportController:

[HttpGet] public virtual ActionResult Index(int id, Dictionary<string,string> filtersVal = null) { ... } 

When I try to call the page as follows: http://domain.com/report/index?id=1 It correctly processes the action, but fills the filerVal parameter using MVC routing information similar to the following:

[0] = {[controller, report]} [1] = {[action, index]}

How can I avoid this, so that the filterVal parameter remains zero.

Please note that: we recently switched to MVC5 .. it worked fine in MVC3 Also: if I call the same action: http://domain.com/report/index?id=2&filterVal[0†.Key=136&filterVal [0] .Value = 1 Then it has the correct value in the "filterVal" parameter.

Can anyone suggest how can I avoid the first scenario?

Thanks.

+5
source share
1 answer

If there is an entry in the route table:

{controller}/{action}/{id}

where {id} is optional, you should visit your page using the URL:

http://yourdomain.com/index/1?xxx=yyy&aaa=bbb

Where xxx=yyy and aaa=bbb becomes the value in filtersVal .

-1
source

Source: https://habr.com/ru/post/1208207/


All Articles