Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net Mvc4查询字符串参数不工作_Asp.net_Asp.net Mvc 4_Asp.net Mvc Routing - Fatal编程技术网

Asp.net Mvc4查询字符串参数不工作

Asp.net Mvc4查询字符串参数不工作,asp.net,asp.net-mvc-4,asp.net-mvc-routing,Asp.net,Asp.net Mvc 4,Asp.net Mvc Routing,在Asp.net MVC4中,我创建了下面的URL,显示了IIS8.0的404错误 http://{ParentURL}/Areas/Admin/Menu/Index?actoin=Add 请帮助我。您的URLhttp://{ParentURL}/Areas/Admin/Menu/Index?mode=Add转到: 区域:管理员 控制器:菜单 操作+视图:索引 参数:模式 因此,在MenuController.cs(管理区域下)中,您应该有以下内容: public ActionResult In

在Asp.net MVC4中,我创建了下面的URL,显示了IIS8.0的404错误

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


请帮助我。

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

区域:管理员

控制器:菜单

操作+视图:索引

参数:模式

因此,在MenuController.cs(管理区域下)中,您应该有以下内容:

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

将URL更改为:
http://{ParentURL}/Admin/Menu/Index?mode=Add

操作的参数必须与路由声明中的名称相同。 另一个错误是在URL中使用
区域
,您可以将其删除或更改默认路径

控制器:

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

路线:

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

您需要在路由配置中设置路由:

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

将此添加到根配置中,然后重试。。是否工作

是否使用默认路线?你应该在“管理”区域有一个“菜单”控制器,操作/视图应该是“索引”。问题是只有查询sring参数,只有其他方面工作正常,但当我通过?mode=Add时,404错误就来了?所以我有了新的路由?控制器====================================================公共操作结果索引(字符串模式){返回视图(ViewMenuModel);}视图===============================================var-JsSuccessAction='@Url.Content(“~/Areas/Admin/Menu/Index?mode=Add”);public override void RegisterArea(AreaRegistrationContext){context.MapRoute(“Admin_default”,“Admin/{controller}/{action}/{id}”,new{action=“Index”,id=UrlParameter.Optional});}查看我更新的答案。是的,您不需要区域名称,如果您需要,您必须将其添加到路由声明中。是的,正确的区域正在创建问题。我还需要使用Routes.config添加,它已添加到管理区域路由。您的路由错误,他需要在路由中添加“Admin”,请查看我的答案。
context.MapRoute(
    "Areas",
    "Areas/{controller}/{action}/{id}",
    new { action = "Index", id = UrlParameter.Optional }
);