2

I have read the other post about this at T4MVC OptionalParameter values implied from current context and I am using the latest T4MVC (2.11.1) which is suppose to have the fix in. I even checked checked to make sure that it's there -- and it is.

I am still getting the optional parameters filled in based on the current context.

For example: Let's say I have a list that is by default ordered by a person's last name. I have the option to order by first name instead with the URL

http://localhost/list/stuff?orderby=firstname

When I am in that page, I want to go back to order by first name with the code:

@Html.ActionLink("order by last name", MVC.List.Stuff(null))

the link I wanted was simply

http://localhost/list/stuff

without any parameters to keep the URL simple and short - invoking default behaviors within the action. But instead the orderby is kept and the url is still

http://localhost/list/stuff?orderby=firstname

Any help would be great. I know that in the most general cases, this does remove the query parameter - maybe I do have a specific case where it was not removed. I find that it only happens when I have the URL inside a page that I included with RenderPartial.

My actual code is

<li>@Html.ActionLink("Recently Updated",  MVC.Network.Ticket.List(Model.UI.AccountId, "LastModifiedDate", null, null, null, null, null))</li>
<li>@Html.ActionLink("Recently Created",  MVC.Network.Ticket.List(Model.UI.AccountId, "CreatedDate", null, null, null, null, null))</li>
<li>@Html.ActionLink("Most Severe",       MVC.Network.Ticket.List(Model.UI.AccountId, "MostSevere", null, null, null, null, null))</li>
<li>@Html.ActionLink("Previously Closed", MVC.Network.Ticket.List(Model.UI.AccountId, "LastModifiedDate", null, "Closed", null, null, null))</li>

the problem happens when someone clicks Previously Closed and and go to ?status=closed. When they click Recently Updated, which I want the status parameter gone (passed a null). But ?status=closed stays in the generated url.

Any insight would be greatly appreciated.

Update 10/16/12

the code:

@html.action("Profile", MVC.Profile.Index())

generated the url:

http://localhost:55059/network/ticket/14441327-128b-e111-af72-0050569e0924?Controller=profile&Action=index

This only happens on a specific page. This is pretty dangerous actually...

Community
  • 1
  • 1
Itakou
  • 23
  • 4

2 Answers2

0

From what I can piece together from online sources, this behavior is not attributable to T4MVC but to the MVC framework itself. Something about which helper functions T4MVC uses. In my project, I just switched over to the vanilla MVC syntax. Monkeying with the anonymous object being passed in as routeValues will give you explicit control over the query string parameters. Doing something like the following will always work:

@Html.ActionLink("Recently Updated", "Ticket", "Network", new { Id = Model.UI.AccountId, orderby = "LastModifiedDate" }, null))

...and generate HTML like this:

<a href="http://localhost:55059/Network/Ticket/14441327-128b-e111-af72-0050569e0924?orderby=LastModifiedDate">Recently Updated</a>
0

If someone still face this issue, here is what I found solution

http://yaweriqbal.wordpress.com/2014/05/25/actionlink-passing-parameter-as-querystring/

user576510
  • 5,777
  • 20
  • 81
  • 144