2013-08-12 49 views
0

在Asp.net MVC4我在下面的網址顯示與IIS8.0Mvc4查詢參數不工作

HTTP 404錯誤創建:// {} ParentURL /地區/管理/菜單/索引actoin =添加

請幫我就可以了。

+0

你使用默認路由?你應該有一個「菜單」控制器「管理員」區域和動作/視圖應該是「指數」。 – glautrou

+0

** [檢查此郵政](http://stackoverflow.com/questions/17802820/customize-url-in-mvc-not-working/17803140#17803140)** –

+0

問題是與僅查詢SRING參數僅其他明智工作正常,但當我通過?mode =添加404錯誤即將到來?所以我有鬃毛新路線? – dotnetexpert

回答

0

您URL http://{ParentURL}/Areas/Admin/Menu/Index?mode=Add去:

地區:聯繫

控制器:菜單

行動+查看:指數

參數:模式

所以在MenuController.cs(下管理區),你應該有這樣的:

public ActionResult Index(string mode) 
{ 
    //code 
    return View(); 
} 

UPDATE:

將網址變更爲:http://{ParentURL}/Admin/Menu/Index?mode=Add

你行動的參數必須有與您的路由聲明中的名稱相同。 也是另一個錯誤是在你的URL中使用Areas,你可以將其刪除或更改默認路由。

控制器:

public ActionResult Index(string mode) 
{ 
    return View(ViewMenuModel); 
} 

查看:

var JsSuccessAction = '@Url.Content("~/Admin/Menu/Index?mode=Add")'; 

路線:

public override void RegisterArea(AreaRegistrationContext context) 
{ 
context.MapRoute("Admin_default", "Admin/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional }); 
} 
+0

控制器 ====================== public ActionResult索引(字符串模式) { return View(ViewMenuModel); } 查看 ===================== VAR JsSuccessAction =「@ Url.Content(「〜/地區/管理/菜單/指數?模式=添加「)'; 公共覆蓋無效RegisterArea(AreaRegistrationContext上下文) { context.MapRoute( 」Admin_default「, 」管理/ {控制器}/{行動} /(編號)「, new {action =「Index」,id = UrlParameter.Optional} ); } – dotnetexpert

+0

http:// {ParentURL}/Areas/Admin/Menu/Index?mode =添加我需要刪除的區域? – dotnetexpert

+0

看看我的更新答案:是的,你不需要區域名稱,如果你想要的話,你必須將它添加到你的路由聲明中 – glautrou

0

您需要設置路由配置的路由:

context.MapRoute(
    "Areas", 
    "Areas/{controller}/{action}/{id}", 
    new { action = "Index", id = UrlParameter.Optional } 
); 

添加到您的根配置,並嘗試..將工作

+0

我需要添加Routes.config,已添加管理區域路線 – dotnetexpert

+0

您的路線錯誤,他需要在路線中添加「管理員」,請查看我的答案。 – glautrou