2

我有一个 ASP.NET MVC 应用程序,其中也有区域。

对于短 url,我在如下区域的 RouteConfig 中设置了所有带有短 url 的操作方法。

//admin dashboard having short url admin/dashboard
context.MapRoute(
            "admin_dashboard",
            "admin/dashboard",
            new { area = "admin", controller = "admin", action = "dashboard" }
        );

//student list having short url admin/studentlist
        context.MapRoute(
            "student_list",
            "admin/studentlist",
            new { area = "admin", controller = "students", action = "List" }
        );

//new student having short url admin/student/new
        context.MapRoute(
            "student_new",
            "admin/student/new",
            new { area = "admin", controller = "students", action = "RegisterStudent" }
        );

//edit student having short url admin/student/id
        context.MapRoute(
            "student_edit",
            "admin/student/{id}",
            new { area = "admin", controller = "students", action = "RegisterStudent" }
        );

如您所见,我为所有操作方法定义了短 url,除了最后两个调用该方法但返回空白视图外,它也可以正常工作。

        [Route("admin/student/{id}")]
        [Route("admin/student/new")]
        public ActionResult RegisterStudent(string Id)
        {
         ....mycode
         return View("RegisterStudent", mymodel);
        }

问题是它调用该方法没有任何错误,但它没有返回视图。它返回空白视图。为什么会发生这种情况我做错了什么?

4

2 回答 2

1

如果您的请求将发送到您的操作方法,那么路由就没有问题。如果您的操作返回空白View,那么它本身一定有问题View

于 2018-11-01T11:22:21.557 回答
0

id 在路由中默认是一个整数。您正在将其视为字符串。

于 2018-11-01T11:00:57.480 回答