我已經有一個城市參數代表我將在我的數據庫上搜索的城市名稱,當我做mysite/List?city = mycityname時,一切正常,但我正在嘗試做什麼是,我還想通過名字搜索結合城市名稱示例 列表?city = mycityname & firstName = myfirstname。我怎樣才能做到這一點 ?這裏是我對城市的查詢,我也添加了firstname參數,但我並不真正知道如何添加它,因此它會過濾兩者。多參數asp網絡mvc 4
public string CurrentFirstName { get; set; }
public ViewResult List(string city, string firstName, int page = 1)
{
UsersListViewModel model = new UsersListViewModel
{
Users = repository.Userss
.Where(p =>city == null || p.CityName == city)
.OrderBy(p => p.UsersId)
.Skip((page - 1) * PageSize)
.Take(PageSize),
PagingInfo = new PagingInfo
{
CurrentPage = page,
UsersPerPage = PageSize,
TotalUsers = repository.Userss.Count()
},
CurrentCity = city
// CurrentFirstName = firstName
};
return View(model);
}