Base controller method

2019-08-02 11:55发布

问题:

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.

回答1:

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