5

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.

1 Answer 1

2

Try clearing the route values explicitly:

RoleListUrl = Url.Action("RoleList", "Person", new { Area = "PersonArea", int1 = "", int2 = "", int3 = "" }),
Sign up to request clarification or add additional context in comments.

2 Comments

Strange. So in the controller the first time that generates a url without the 3 ints and the second time it generates it with the last sent values? You put a breakpoint directly on that line to verify?
This doesn't work for me. Instead when this is done, the old parameters appear after the url: example: http:www.test.com/Page?OldParameter=xxxxx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.