我在控制器中有下一个方法:
public ViewResult List(string category, string price, string SelectedValue, int page = 1)
{
ViewBag.CurrentSort = SelectedValue;
var Furnitures = repository.Furnitures
.Where(p => category == null || p.Category.Name == category)
.ToList();
if(SelectedValue != null)
{
if (SelectedValue.Equals("OrderByDescending"))
{
Furnitures = Furnitures.OrderByDescending(z => z.Price).ToList();
}
}
Furnitures = Furnitures.Skip((page - 1) * pageSize)
.Take(pageSize).ToList();
ListViewModel model = new ListViewModel
{
Furnitures = Furnitures,
InfoPages = new InfoPage
{
CurrentPage = page,
ItemsPerPage = pageSize,
TotalItems = category == null ? repository.Furnitures.Count() :
repository.Furnitures.Where(furniture => furniture.Category.Name == category).Count()
},
CurrentCategory = category,
Fields = new List<SelectListItem>
{
new SelectListItem { Text = "Order By Descending", Value = "OrderByDescending" },
new SelectListItem { Text = "Order By Ascending", Value = "OrderByAscending" },
}
};
return View(model);
}
我尝试使用Ajax按下拉列表过滤器来订购产品列表。这是我在View中的代码:
@using (Ajax.BeginForm("List", "Furniture", new AjaxOptions { UpdateTargetId = "content" , Confirm = "Выполнить AJAX-запрос?" , InsertionMode = InsertionMode.Replace }))
{
@Html.DropDownListFor(x => x.SelectedValue,
new SelectList(Model.Fields, "Value", "Text", Model.SelectedValue), "-- Select Product--")
<input type="submit" value="Display" />
}
我的问题是当我提交表单时,我在控制台中收到错误:
jquery-3.1.1.js:9536 POST http://localhost:61741/ 404 (Not Found)
我不明白为什么我会收到此错误。我下载了Nuget Package jquery.unobtrusive-ajax并在我的View中包含了脚本但仍然出错。也许参数有问题,也许我应该将它们传递给控制器?谢谢!
答案 0 :(得分:0)
尝试以下方法: