我正在JqueryUI選項卡中進行搜索。該選項卡包含Ajax搜索表單和顯示搜索結果的表格。此外,我使用IpagedList來遍歷結果表。控制器的Index行爲包含Linq查詢並控制要呈現的視圖。下面是Index操作的代碼:區分兩個Ajax請求
public ActionResult Index(ConsultantSearch model, int page = 1)
{
if (!String.IsNullOrEmpty(model.SearchButton) ||!String.IsNullOrEmpty(model.CancelButton))
{
var consultants = from con in db.Consultants
where (model.ConsultantName == null || con.ConsultantName.Contains(model.ConsultantName)) && (model.CompanyID == null || con.CompanyID == model.CompanyID)
&& (model.ClientID == null || con.ClientID == model.ClientID) && (model.VendorID == null || con.VendorID == model.VendorID) && (model.RecruiterID == null || con.RecruiterID == model.RecruiterID)
&& (model.Class == null || con.Class == model.Class) && (model.W2_1099 == null || con.W2_1099 == model.W2_1099) && (model.IsActive == null || con.IsActive == model.IsActive)
&& (model.StartDate == null || model.EndDate == null || (con.StartDate >= model.StartDate && con.EndDate <= model.EndDate))&&(model.StartDate == null || con.StartDate >= model.StartDate) && (model.EndDate == null|| con.EndDate <= model.EndDate)
select con;
consultants = consultants.Include(c => c.Client).Include(c => c.Company).Include(c => c.Recruiter).Include(c => c.SalesPerson).Include(c => c.Vendor);
return PartialView("_ConsultantList",consultants.ToList().ToPagedList(page,RecordsPerPage));
}
else
{
var consultants = db.Consultants.Include(c => c.Client).Include(c => c.Company).Include(c => c.Recruiter).Include(c => c.SalesPerson).Include(c => c.Vendor);
return PartialView(consultants.ToList().ToPagedList(page, RecordsPerPage));
}
}
當用戶第一次加載頁面的其他部分執行這使得其顯示形式和顯示當前數據庫中的所有顧問表的局部視圖索引。但是,如果單擊搜索按鈕或取消按鈕,則if條件變爲true,並呈現局部視圖Consultant列表。其中只更新頁面的結果表部分。現在
我的問題是我想補充,其中當尋呼控制使用。如果條件得到滿足的條件,只有在結果表顧問記錄下頁所示。我可以在If條件中使用isAjaxRequest()。但問題是,當jQueryUI的標籤(含從和表)將加載,因爲isAjaxRequest(),只有諮詢列表視圖會被渲染,我不希望的。如果條件將成爲現實。
所以基本上我想區分兩個ajax請求。如果ajax請求是爲選項卡,那麼else條件應該工作,如果它是從分頁,然後if條件應該工作。 任何想法...?
謝謝...這將使我的代碼更清潔並解決我的問題。 – sar