Asp Net MVC 5进程多选搜索

时间:2015-03-31 11:52:01

标签: asp.net-mvc

我试图找出如何将n个选定的选项发送到控制器并返回包含这些选项的视图。

public ViewResult SearchAndFilters(string sortOrder, string currentFilter, string searchString, int? page, ViewModel model)
{
    //pagination things

    if (model.CountryFilter != null)
    {
        //person is the list that contains all the "people", and country is a string
        var countries = person.Where(m => model.CountryFilter.Contains(m.Country));
        myViewModel.person = countries.ToPagedList(pageNumber, pageSize);
    }

    return View("~/Views/Home/SearchAndFilters.cshtml", myViewModel);
}

如果我只通过model.CountryFilter发送一个国家/地区名称,则此代码有效;但如果我发送2个或更多国家/地区名称,则仅处理一个。我需要更改什么才能让我的搜索返回来自A国和B国的所有人?

这是我的观点:

@using (Html.BeginForm("SearchAndFilters", "Person", FormMethod.Get))
{
    <p>

    @Html.DropDownListFor(m => m.CountryFilter, Model.CountryList, new { @class = "chosen", multiple = "multiple", style = "width: 250px;", data_placeholder = "Countries" })

    </p>

    <input type="submit" name="SearchLists" value="Search" /> 
}

0 个答案:

没有答案