我正在页面上实现标签,这些标签应该重新填充位于布局中父级别的下拉列表。我正在使用模型构建器的概念并编写了扩展方法。目前我有一些jquery,当按下选项卡时,对控制器方法执行ajax请求,该方法根据传入的ViewModel返回正确的视图。
但我想在ajax请求上刷新页面,同时保留选项卡但不想播放。如果我执行了location.reload()函数,它将转到控制器方法,一次是ajax,然后是第二次重载。
我不确定如何解决此问题,但我的代码如下:
public ViewResult SalesCustomerOutcome(Args args, string type)
{
args.SelectedTab = type;
return View<SalesCustomerOutcomeBuilder>(args);
}
构建器将构建相关选项,例如下拉菜单,但我确实需要刷新页面。
我的构建器执行以下操作:
args.AvailableViews = null;
if (args.SelectedTab == null)
{
args.SelectedTab = "advice";
}
switch (args.SelectedTab)
{
case "brandProduct":
args.AvailableViews = new List<SelectListItem>
{
new SelectListItem { Text = "By Product", Value = "Product" },
new SelectListItem { Text = "By Brand", Value = "Brand" }
};
break;
case "skill" :
args.AvailableViews = new List<SelectListItem>
{
new SelectListItem { Text = "Applications", Value = "Applications" },
new SelectListItem { Text = "Advances", Value = "Advances" },
new SelectListItem { Text = "Review", Value = "Review" }
};
break;
case "advice":
args.AvailableViews = new List<SelectListItem>
{
new SelectListItem { Text = "Advised", Value = "Advice" },
new SelectListItem { Text = "Non Advised", Value = "NonAdvice" }
};
break;
default:
args.AvailableViews = new List<SelectListItem>
{
new SelectListItem { Text = "By Product", Value = "Product" },
new SelectListItem { Text = "By Brand", Value = "Brand" }
};
break;
}
//Select the first viewtype of current list.
if (args.ViewType == null) args.ViewType = args.AvailableViews.FirstOrDefault().Value.ToString();
var inputGrid = InputGridBuilder.Build(args);
var feedback = FeedbackBuilder.Build(inputGrid.Report.Id);
if (args.ViewType == "Brand")
{
return new SalesCustomerBrandOutcomeVM
{
FeedbackModel = feedback,
InputGrid = inputGrid,
Items = call to stored proc
};
}
else if (args.ViewType == "Product")
{
return (ReportVM)new SalesCustomerProductOutcomeVM
{
FeedbackModel = feedback,
InputGrid = inputGrid,
Items = args.ViewType == "Product" ? Data.GetSalesCustomerProductOutcomeMMR(inputGrid.Employee.ID, inputGrid.DatePeriod).ToList() : Data.GetSalesCustomerBrandProductOutcomeMMR(inputGrid.Employee.ID, inputGrid.DatePeriod, args.ViewType).ToList()
};
}
else if(args.ViewType == "Skills")
{
return (ReportVM)new SalesCustomerSkillOutcomeVM
{
FeedbackModel = feedback,
InputGrid = inputGrid,
Items = //some stuff here which i cannot show
};
}
else
{
return (ReportVM) new SalesCustomerAdviceOutcomeVM
{
FeedbackModel = feedback,
InputGrid = inputGrid,
Items = //call to stored proc
};
}
可用的视图是建立的下拉列表。
jquery的:
function tabItemClicked(a, action) {
var container = $(a).parents('div.tabs');
var resultDiv = $($(a).attr('href'), container);
alert($(a).attr('href'));
//check if a tab has been selected. This helps when page has been refreshed.
var selectedTab = $("#salesTabs").tabs("option", "selected");
var type = null;
if (selectedTab == 0) {
type = "brandProduct";
}
else if (selectedTab == 1) {
type = "advice"
}
$.ajax({
type: "POST",
url: action,
cache: false,
data: { type: type },
success: function (html) {
//location.reload();
/*resultDiv.html = ('');
resultDiv.html(html);*/
}
});
所以在ajax请求后我需要刷新菜单但是这可能吗?