這是控制器類。我只顯示方法簽名。Url.Action生成查詢而不是參數URL
[Authorize]
[RoutePrefix("specification")]
[Route("{action=index}")]
public class SpecificationController : BaseController
{
[HttpGet]
[Route("~/specifications/{subcategoryID?}")]
public ActionResult Index(int? subcategoryID);
[HttpPost]
[Route("get/{subcategoryID?}")]
public JsonResult Get(int? subcategoryID);
[HttpGet]
[Route("~/specifications/reorder/{subcategoryID}")]
public ActionResult Reorder(int subcategoryID);
[HttpGet]
[Route("new/{id?}")]
public ActionResult New(int? id);
[HttpGet]
[Route("edit/{id?}")]
public ActionResult Edit(int id);
[HttpPost]
[ValidateAntiForgeryToken]
[Route("edit")]
public JsonResult Edit(SpecificationJson specification);
[HttpPost]
[Route("moveup")]
public JsonResult MoveUp(int specificationID);
[HttpPost]
[Route("movedown")]
public JsonResult MoveDown(int specificationID);
[HttpDelete]
[Route]
public ActionResult Delete(int id);
}
的問題是,調用
@Url.Action("index", "specifications", new RouteValueDictionary() { { "subcategoryID", @subcategory.SubcategoryID } })
回報
規格?而不是/subcategoryID = 15
/規格/ 15
這究竟是爲什麼?在這條路線上我沒有任何類似的方法期待這個!
我知道,如果我按照你說的那樣做,它就會起作用。之前就是這樣。爲了更加一致,我決定,當我返回所有結果時,它應該說/規範而不是/規範,因爲後者意味着它只是我們正在討論的一個規範。此外,我認爲通過在路由屬性中使用〜/ specifications,我明確表示我正在重新啓動路由,而不是使用控制器中指定的路由前綴。 – Rob
是的,但爲了使其工作,您必須將操作方法移至名爲'SpecificationsController'的控制器。通過沒有正確指定它,你會得到一個路由未命中並且它與另一條路由相匹配,這就是爲什麼你正在查詢字符串。 – NightOwl888
這工作就像一個魅力。我認爲改寫路線會完全重新編寫它。看起來你是對的! – Rob