ASP.NET MVC路由“无法找到资源”

时间:2016-12-23 09:37:32

标签: asp.net-mvc url-routing

我有一个控制器,它继承自基本控制器和默认路由:

 routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
进入/Departments / Create时

正常工作:

public class DepartmentsController : BaseController
{

    public ActionResult Create()
    {
        return View("Create");
    }

public abstract class BaseController : Controller
{
....

但是,如果我尝试将其更改为通用控制器,例如

public class DepartmentsController<T> : BaseController<T>
    where T: class
{

    public ActionResult Create()
    {
        return View("Create");
    }

public abstract class BaseController<T> : Controller
    where T: class
{
....

然后转到/ Departments / Create我最终得到“无法找到资源”错误,表明尚未找到该操作。但是,当我检查routeDebugger使用的路由时,我可以看到“{controller} / {action} / {id}”已匹配,但尚未调用该操作:

MVC Route

我是否需要使用不同的路线或方法来调用正确的动作?

谢谢!

0 个答案:

没有答案