简体   繁体   English

Mvc4 Querystring参数不起作用

[英]Mvc4 Querystring parameter is not working

In Asp.net MVC4 I have created below URL showing 404 error with IIS8.0 在Asp.net MVC4中,我已经在URL下创建了IIS8.0,显示404错误

http://{ParentURL}/Areas/Admin/Menu/Index?actoin=Add http:// {ParentURL} / Areas / Admin / Menu / Index?actoin =添加

Please help me on it. 请帮我。

You URL http://{ParentURL}/Areas/Admin/Menu/Index?mode=Add goes to: 您的网址http://{ParentURL}/Areas/Admin/Menu/Index?mode=Add转到:

Area: Admin 区域:管理员

Controller: Menu 控制器:菜单

Action + View: Index 动作+检视:索引

Parameter: mode 参数:模式

So in MenuController.cs (under Admin area) you should have this: 因此,在MenuController.cs中(在“管理”区域下),您应该具有以下功能:

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

UPDATE: 更新:

Change your URL to: http://{ParentURL}/Admin/Menu/Index?mode=Add 将您的URL更改为: http://{ParentURL}/Admin/Menu/Index?mode=Add

The parameters of your Action must have the same name as in your route declaration. Action的参数必须与路由声明中的名称相同。 Also another mistake is to use Areas in your URL, you can remove it or change your default route. 另一个错误是在URL中使用Areas ,您可以将其删除或更改默认路由。

Controller: 控制器:

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

View: 视图:

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

Route: 路线:

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

You need to set a route in route config : 您需要在route config中设置一条路由:

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

add this to your root config and try .. will work 将此添加到您的根配置,并尝试..将工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM