2016-01-11 104 views
0

为什么Route属性隐藏|应用于其他方法?路由属性隐藏动作

[HttpGet] 
[Route("Issues/ReportIssue")] 
public ActionResult ReportIssue() 

行动没有Route属性停止工作

[HttpPost] 
public ActionResult ReportIssue(IssueModel viewModel) 

jQuery返回 “未找到” 错误

如果重命名Post行动或添加Route属性,所有的作品。 Route属性是否有任何优先权规则?

回答

0

我尝试下面的代码示例 -

[HttpGet] 
[Route("Products/Create")] 
public ActionResult Create() 
{ 
     ProductCategory category = new ProductCategory(); 
     category.ProductCategoryId = 1; 
     return View(category); 
} 

[HttpPost] 
public ActionResult Create(ProductCategory category) 
{ 
     return View(category); 
} 

,我可以看到这个工作正常,没有任何问题。在我的情况下,控制器名称是“Product”,如果我将Route属性指定为“Products/Create”(与控制器名称不同)或“Product/Create”,则下面的代码工作。所以不知道,为什么你会面临这个问题。

获取和发布操作应该在没有路由属性的情况下工作,因为它们正在工作。属性路由是MVC 5中新增加的内容,并且可以更好地控制路由。但是,这仍然不是强制性的。传统的路线应该很好。

看一看 - http://blogs.msdn.com/b/webdev/archive/2013/10/17/attribute-routing-in-asp-net-mvc-5.aspx文章。

+0

你可以通过jquery ajax调用来检查它吗 – GSerjo