Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc url action ignore 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'm using in my controller like this:

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

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

In my view, i have drop downs that will fill in the int1, int2, and int3 values. I'm using JavaScript in the client to fill out the rest of the URL:

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

This is working great the first time, but when the page reloads, the old values (12, 43, 76) get re-used when creating the base url in my controller. So, when user interacts with dropdowns the following URL gets created on client:

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

How do I get Url.Action to ignore the old values (12, 43, 76) on subsequent posts to the server so the client can construct the correct url? I'm resorting to hard coding the base url ("/PersonArea/Person/RoleList/") in the controller instead.

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.

like image 364
Tom Schreck Avatar asked Nov 05 '22 04:11

Tom Schreck


1 Answers

Try clearing the route values explicitly:

RoleListUrl = Url.Action("RoleList", "Person", new { Area = "PersonArea", int1 = "", int2 = "", int3 = "" }),
like image 164
Lester Avatar answered Nov 11 '22 16:11

Lester