views:

249

answers:

3

I am trying to provide a link to filter search results.

    <%= Html.ActionLink("Filter Results", "Index", new { page = Model.RestaurantList.PageIndex(), searchText = Model.SearchText, useFilter = true, filterOption = Model.FilterOption, filterText = Model.FilterText }, null)%>

The controller definition is as such

 public ActionResult Index(int? page, string searchText, bool useFilter, string filterText, string filterOption)

However when I debug this the values are not set properly, even the useFilter variable.

My link is rendered localhost/home/index/true?page=0

Any ideas how to fix this?

A: 

It looks like it should work.

Have you verified that the model fields you are passing to the ActionLink actually contain data?

Robert Harvey
+2  A: 

The code segment looks fine. I think there are 2 possible errors:

  1. Wrong route information: check the routes.MapRoute(...) calls in global.ascx.cs/vb file to make sure a route for Home#Index action is properly configured
  2. Wrong controller: try use the overload of ActionLink which explicitly specifies a controller

If you still can't make it to work, you might want to post more info (like route mapping code, name of view/controller)

Buu Nguyen
It was a route problem. I overlooked the order I was adding the routes.
dean nolan
A: 

However when I debug this the values are not set properly, even the useFilter variable. My link is rendered localhost/home/index/true?page=0

I think your useFilter parameter is actually rendered. Its mapped to the route I guess.

Try to set a hardcoded value for searchText

<%= Html.ActionLink("Filter Results", "Index", new { page = Model.RestaurantList.PageIndex(), searchText = Model.SearchText, useFilter = true, filterOption = Model.FilterOption, filterText = "the answer" }, null)%>

If it shows up, then you did not set your model in the controller.

Malcolm Frexner