나는 ASP MVC 4에서 프로젝트를 진행하고 있습니다. 며칠 전 나는 이상한 문제를 겪었다. 나는 ~/Dashboard/index로 인덱스를 호출 할 때 컨트롤러 "대시 보드"를 가지고 있지만 정상적으로 작동하지만 ~/대시 보드로 호출하면 HTTP 404 오류를 찾을 수 없습니다.Asp MVC 4 동작을 찾을 수 없습니다.
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "UI.Web.Controllers" }
);
심지어 대시 보드 컨트롤러에 대한 경로 설정을 추가하지만 내 관리 지역의 일부 컨트롤러에 문제
routes.MapRoute(
name: "Dashboard",
url: "Dashboard/{action}/{id}",
defaults: new { controller = "Dashboard", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "UI.Web.Controllers" }
);
같은 종류 작동하지 않습니다 (일부는 잘 작동하고 일부는 제공 HTTP 404 . 오류를 찾을 수 없습니다 내 지역 경로 설정은 다음과 같습니다
context.MapRoute(
"DMS_Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Contact", action = "Index", id = UrlParameter.Optional },
new string[] { "UI.Web.Areas.Admin.Controllers" }
);
관리 지역의 일부 컨트롤러의 index 액션이 작동하지 않는 하나의 컨트롤러는 AddEdit의 작용을 갖는 것을 알 그래서 일하지 않아. 내가 그것을 작동 ~/관리/사용자/AddEdit/A로 전화를하지만 난 ~/관리자/사용자로 호출하는 경우/그것을 AddEdit 경우 AddEdit 활동에
public ActionResult AddEdit(string id)
{
var user = new Models.RegisterModel();//string.IsNullOrWhiteSpace(id) ? new Models.RegisterModel() : Membership.GetUser(id);
if (!string.IsNullOrWhiteSpace(id))
{
var obj = Membership.GetUser(id);
if (obj != null)
{
user.Email = obj.Email;
user.UserName = obj.UserName;
}
}
ViewBag.PageTitle = string.IsNullOrWhiteSpace(id) ? "Add User" : "Edit User";
ViewBag.IsAjax = Request.IsAjaxRequest();
if (Request.IsAjaxRequest())
return PartialView("~/Areas/Admin/Views/Users/AddEditPartial.cshtml", user);
return View("~/Areas/Admin/Views/Users/AddEdit.cshtml", user);
}
또한 HTTP 404 찾을 수 없음 오류가 있습니다.
일부 프레임 워크 업데이트 문제 또는 코드 문제로 인해이 동작이 발생합니까? 어떤 생각이든 .... 동일한 코드가 이전에 작동했기 때문에 이것이 코딩 문제라고 생각하지 않습니다 ......
이제는 내 프로젝트를 끝내고 여기 마지막 단계에서 붙어 있습니다.
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Dashboard",
url: "Dashboard/{action}/{id}",
defaults: new { controller = "Dashboard", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "UI.Web.Controllers" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "UI.Web.Controllers" }
);
을 내 AdminAreaRegistration 코드 :
Tieson T. 코멘트에서 지적context.MapRoute(
"DMS_Users",
"Admin/Users/{action}/{id}",
new { controller = "Users", action = "Index", id = UrlParameter.Optional },
new string[] { "UI.Web.Areas.Admin.Controllers" }
);
context.MapRoute(
"DMS_Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Contact", action = "Index", id = UrlParameter.Optional },
new string[] { "UI.Web.Areas.Admin.Controllers" }
);
노선이 문제를 추가하는 순서; 질문을 편집하여 RouteConfig 파일에 표시된대로 경로를 표시하십시오. –