【发布时间】:2017-04-28 06:38:18
【问题描述】:
在调用Html.DisplayNameFor 时,我们只需提供一个 lambda 表达式来呈现,例如通过item => Model.Name 呈现学生姓名。
由于编译时检查,这种方法非常好。
如何使RedirectToAction 也成为可能,例如RedirectToAction(controller => Controllers.Student.Index) 而不是RedirectToAction("Index")?假设名为 Controllers 的属性包含项目中使用的所有控制器。
【问题讨论】:
-
看看这个:stackoverflow.com/questions/2102757/… 虽然这些库看起来很旧,但我不知道它们是否仍然适用于最新版本的 ASP.NET
-
如果属性 Controllers.Student.Index 是正确的(或者你可以得到类似的属性),你可以简单地使用 RedirectToAction(nameof(Controllers.Student.Index))