我正在尝试找到一种方法来检查 2 个不同表中的结果(searchTern)并传递给 partial view 。我得到的错误是局部视图只能接受 2 个参数。我该怎么做 ?
public ActionResult index(string searchTerm)
{
var model = db.museum.OrderBy(c => c.SynCity)
.Where(r => searchTerm == null || r.SynCity.StartsWith(searchTerm))
.Select(r => new TheViewModel
{
SynStyle = r.SynStyle,
SynAddress = r.SynAddress,
SynNeighborhood = r.SynNeighborhood,
SynCity = r.SynCity,
SynName = r.SynName,
});
var model2 = db.sites.OrderBy(s => s.cityName)
.Where(d => d.cityName.StartsWith(searchTerm))
.Select(d => new TheViewModel
{
cityName = d.cityName,
attendant1Phone = d.attendant1Phone,
address = d.address,
name = d.name,
phone = d.phone
});
if (Request.IsAjaxRequest())
{
return PartialView("_Guid", model, model2);
}
return View(model, model2);
}
视图模型
public class TheViewModel {
public int SId { get; set; }
public string SynCity { get; set; }
public string SynName { get; set; }
public string SynStyle { get; set; }
public string SynAddress { get; set; }
public string SynNeighborhood { get; set; }
public string name { get; set; }
public string cityName { get; set; }
//more string Parameters
}