【问题标题】:.net MVC 2 controller inheritance.net MVC 2 控制器继承
【发布时间】:2011-09-30 09:43:06
【问题描述】:

例如,我对控制器的继承有一点问题:

public class AController: Controller {
 public ActionResult Index(long id)
        {
            return Index(id, isComposite);
        }
}
public class BController : AController {


}

当我单击 ../B/Index/12 时,出现以下异常:未找到视图“索引”或其主视图。搜索了以下位置:~/Views/B/Index.aspx 我可以将 Index.aspx 复制到“共享”地图中,但可能还有其他解决方法吗? 谢谢 。

【问题讨论】:

    标签: asp.net-mvc-2


    【解决方案1】:

    您可以将它放在~/Views/Shared/Index.aspx 中,但在 ASP.NET MVC 中最好避免这种类型的控制器继承。

    【讨论】:

    • 为什么?如果我有一些通用功能?
    • @user872761,在 ASP.NET MVC 中还有其他实现通用功能的方法:动作过滤器、模型绑定器、存储库……当然取决于您愿意实现的通用功能。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-27
    • 2013-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-01
    相关资源
    最近更新 更多