基本控制器方法 [英] Base controller method

查看:155
本文介绍了基本控制器方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是没有得到执行我的基本控制器方法。下面是我的基本控制器。

 公共抽象类ReportServiceBaseController:控制器
{
    保护ReportServiceBaseController();    [HttpPost]
    公共JsonResult LoadDocumentInfo(LoadDocumentInfoRequest要求);    [HttpPost]
    公共JsonResult LoadDocumentMapInfo(LoadDocumentMapInfoRequest要求);
}

下面是我的派生的控制器:

 公共类ReportController:ReportServiceBaseController
{
    保护覆盖PerpetuumSoft.Reporting.WebViewer.Server.ReportServiceBase CreateReportService()
    {
        返回新ServiceClass();
    }    [HttpPost]
    公共JsonResult LoadDocumentInfo(LoadDocumentInfoRequest要求)
    {
        返回base.LoadDocumentInfo(请求);
    }
}

如果我从派生类删除LoadDocumentInfo方法,那么它没有得到调用。这是越来越电话,当我在派生类中添加相同的名称的方法<​​/ P>

请帮忙。


解决方案

您基类的实现是空的 - 但它也意味着,code不会编译 - 因为没有执行方法,已被标记为摘要

另外,在你的派生的控制器的方法,已被打上覆盖

阅读此为参考:的http:/ /msdn.microsoft.com/en-us/library/ebca9ah3(v=vs.110).aspx

My base controller method is not getting executed. Below is my base controller.

public abstract class ReportServiceBaseController : Controller
{
    protected ReportServiceBaseController();

    [HttpPost]
    public JsonResult LoadDocumentInfo(LoadDocumentInfoRequest request);

    [HttpPost]
    public JsonResult LoadDocumentMapInfo(LoadDocumentMapInfoRequest request);
}

Below is my derived controller :

public class ReportController : ReportServiceBaseController
{
    protected override PerpetuumSoft.Reporting.WebViewer.Server.ReportServiceBase CreateReportService()
    {
        return new ServiceClass();
    }

    [HttpPost]
    public JsonResult LoadDocumentInfo(LoadDocumentInfoRequest request)
    {
        return base.LoadDocumentInfo(request);
    }
}

If I remove LoadDocumentInfo method from derived class then it not getting call. It is getting call when I add same name method in derived class

Please help.

解决方案

Your base class implementation is empty - but it also means that the code won't compile - since the method without implementation has to be marked as abstract.

Also the method in your derived controller has to be marked with override.

Read this for the reference: http://msdn.microsoft.com/en-us/library/ebca9ah3(v=vs.110).aspx

这篇关于基本控制器方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆