我試圖找到一種方法來檢查結果(searchTern)在2個不同的表中並傳遞到局部視圖。我得到的錯誤是部分視圖只能使用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
}
([在一個單一的視圖(#MVC3)多模型]的可能重複http://stackoverflow.com/questions/5763631/multiple -model-in-a-single-view-mvc3) – Amit