我有一个ASP.NET MVC应用程序,其中也包含一些区域。
对于短网址,我在RouteConfig的以下区域中设置了所有带有短网址的操作方法。
//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);
}
问题是它正在调用该方法而没有任何错误,但是它没有返回视图。它返回空白视图。为什么发生这种情况,我没有犯任何错误?
答案 0 :(得分:1)
如果您的请求将转到您的操作方法,那么路由就没有问题。如果您的操作返回的是空白的View
,那么View
本身一定存在问题。
答案 1 :(得分:0)
Id在route中默认为整数。您正在将其视为字符串。