Asp.net mvc url action ignores old parameter values

I have the following route:

context.MapRoute ( "PersonArea_tripleInt", "PersonArea/{controller}/{action}/{int1}/{int2}/{int3}", new { controller = "Person", action = "Index" }, new { int1 = new IntConstraint(), int2 = new IntConstraint(), int3 = new IntConstraint() } ); 

I use the following in my controller:

 RoleListUrl = Url.Action("RoleList", "Person", new { Area = "PersonArea" }), 

To create this url: "/ PersonArea / Person / RoleList"

In my opinion, I have drop-down lists that will populate the values โ€‹โ€‹of int1, int2 and int3. I use JavaScript in the client to populate the rest of the url:

"/ PersonArea / Person / RoleList / 12/43/76"

This works fine for the first time, but when the page reloads, the old values โ€‹โ€‹(12, 43, 76) are reused when creating the base url in my controller. Thus, when the user interacts with the drop-down lists, the following URL is created on the client:

"/ PersonArea / Man / RoleList / 12/43/76/88/154/78"

How to force Url.Action to ignore old values โ€‹โ€‹(12, 43, 76) on subsequent messages on the server so that the client can create the correct URL? I resort to hard coding the base url ("/ PersonArea / Person / RoleList /") in the controller.

I just want the controller to produce "/ PersonArea / Person / RoleList" every time and let the client fill in the rest of the parameters.

What am I missing? Thanks.

+4
source share
1 answer

Try to explicitly clear the route values:

 RoleListUrl = Url.Action("RoleList", "Person", new { Area = "PersonArea", int1 = "", int2 = "", int3 = "" }), 
+1
source

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


All Articles