ASP.NET MVC 区域 return 空白视图
ASP.NET MVC areas return blank view
我有一个 ASP.NET MVC 应用程序,其中也有区域。
简而言之 url 我在如下区域的 RouteConfig 中设置了短 urls 的所有 actionmethods 路由。
//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" }
);
如您所见,我已经为所有操作方法定义了短 urls,它也工作正常,除了最后两个调用该方法但 returns 空白视图。
[Route("admin/student/{id}")]
[Route("admin/student/new")]
public ActionResult RegisterStudent(string Id)
{
....mycode
return View("RegisterStudent", mymodel);
}
问题是调用方法没有任何错误,但没有返回视图。它 returns 空白视图。为什么会这样是不是我做错了?
路由中id默认为整数。您正在将其视为字符串。
如果你的请求是去你的action方法,那么路由是没有问题的。如果您的操作返回空白 View
那么,一定是 View
本身有问题。
我有一个 ASP.NET MVC 应用程序,其中也有区域。
简而言之 url 我在如下区域的 RouteConfig 中设置了短 urls 的所有 actionmethods 路由。
//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" }
);
如您所见,我已经为所有操作方法定义了短 urls,它也工作正常,除了最后两个调用该方法但 returns 空白视图。
[Route("admin/student/{id}")]
[Route("admin/student/new")]
public ActionResult RegisterStudent(string Id)
{
....mycode
return View("RegisterStudent", mymodel);
}
问题是调用方法没有任何错误,但没有返回视图。它 returns 空白视图。为什么会这样是不是我做错了?
路由中id默认为整数。您正在将其视为字符串。
如果你的请求是去你的action方法,那么路由是没有问题的。如果您的操作返回空白 View
那么,一定是 View
本身有问题。