views:

39

answers:

1

i have an asp.net mvc page where i show a dataset in a report. I have a filter section at the top and each filter changes the dataset from:

 Controller/Action

to something like this:

Controller/Action/Field1Filter

If there is no filter selected, i put a zero in this part of the url. I keep adding more fields to filter by and now i end up with this type of URL.

Controller/Action/Field1Filter/Field2Filter/Field3Filter/Field4Filter/Field5Filter/Field6Filter . . . .

so i end up with URLs like this:

Controller/Action/0/0/1/0/5/0

Is there anyway to do this as:

  1. I am going to be adding some more fields to filter by
  2. I want to support multiselect for some of these fields so i dont see how i can support this in the current model
+1  A: 

Example from my application:

[HttpGet]
public ActionResult TaskSearch(TaskSearchCriteria criteria)
{
    //Do something with criteria
}

public class TaskSearchCriteria
{
    public List<int> Statuses { get; set; } //List of ids

    public DateTime? CreationDateFrom { get; set; }
    public DateTime? CreationDateTo { get; set; }

    public bool SearchInTitle { get; set; }
}

Part of form:

<form method="GET" action="/Task/TaskSearch" name="searchform">
    <select id="Search_Statuses" multiple="multiple" name="Statuses">
        <option value="-1">*All</option>
        <option value="-8">*Opened</option>
        <option value="-4">*Active</option>
        <option value="-3">*Closing</option>
        <option value="-2">*Beginning</option>
        <option value="21">Closed</option>
        <option value="19">Created</option>
        <option value="20">In progress</option>
        <option value="22">Requires testing</option>
    </select>

Example query string:

SearchInTitle=true&SearchInTitle=false&Statuses=19&Statuses=20&Statuses=22&CreationDateFrom=2010.07.01

If you pass one field many times, it will be translated to Array.

LukLed