【发布时间】:2015-05-05 12:55:11
【问题描述】:
在我的产品控制器中,我有两个 actionresult 返回方法:
[Route("Shop/{brand}/{category}/{subcategory?}/{page:int?}")]
public ActionResult Index(string brand, string category, string subcategory, int? page, SortOptions currentSort = SortOptions.SinceDesc)
{ //...
和
[HttpPost]
[Route("Shop/{brand}/{category}/{subcategory?}/{page:int?}")]
public ActionResult Index(ProductsViewModel pvm)
{ //...
这是我的观点:
@using (@Html.BeginForm("Index", "Products", FormMethod.Post))
{
@Html.DropDownListFor(x => x.SubCatID, Model.SubCategoriesSelectList, new { @class = "multiselect" })
}
当我提交页面时,它会点击 httppost 方法,但 url 仍然是:Shop/nike/shoes,即使我从下拉列表中选择了子类别 runningshoes。 我想要这样的网址:
- 商店/耐克/鞋子
- 商店/耐克/鞋子/跑鞋
作为一个 webform-guy,我很难导航到新的 url 并使用 viewmodel 属性作为参数。
edit 发布了我的 UI: 解释我的用户界面:
第一个下拉菜单应该get 到一个子类别。例如:shop/nike/shoes/runningshoes
第二个应该发布“返回”以对产品进行排序。
价格滑块应该回传,因为它应该过滤。 (如果没有分页,将过滤客户端)
分页应该得到,这样您就可以深度链接到某个页面:shop/nike/shoes/runningshoes/page2 等。
【问题讨论】:
-
表单值不会反映在路由中(幸运的是)。如果您想要基于所选子类别的 url,则需要重定向到 GET 方法(传递参数)
标签: asp.net-mvc-5 asp.net-mvc-routing razor-2 asp.net-mvc-viewmodel