我的模型可以继承Controller类吗?

时间:2014-02-26 07:21:28

标签: asp.net-mvc model controller

我想使用Controller类的Json方法,所以我可以将JsonResult传回Controller ...就像这样(这是我的模型类中的方法):

public JsonResult GetJsonResultByName(string collectionName)
    {
        JsonResult returnJsonResult = new JsonResult();

        switch (collectionName)
        {
            case "homeMyClientsProspectsGrid":
                returnJsonResult = Json(homeData.myClients, JsonRequestBehavior.AllowGet);
                break;
            case "revenueMyRevenueGrid":
                returnJsonResult = Json(revenueData.myRevenueClients, JsonRequestBehavior.AllowGet);
                break;
            case "revenueMyBacklogGrid":
                returnJsonResult = Json(revenueData.myBacklogClients, JsonRequestBehavior.AllowGet);
                break;
            case "salesMyYTDSalesGrid":
                returnJsonResult = Json(salesData.myYTDSalesClients, JsonRequestBehavior.AllowGet);
                break;
            case "salesMyYTDCostOfSalesGrid":
                returnJsonResult = Json(salesData.myYTDCostOfSalesClients, JsonRequestBehavior.AllowGet);
                break;
            case "salesMyActiveOpportunitiesGrid":
                returnJsonResult = Json(salesData.myActiveOpportunityClients, JsonRequestBehavior.AllowGet);
                break;
            case "projectsMyPTDProjectStatusGrid":
                returnJsonResult = Json(projectData.myPTDProjectStatusClients, JsonRequestBehavior.AllowGet);
                break;
            case "projectsMyBillingsAndCollectionsGrid":
                returnJsonResult = Json(projectData.myBillingsAndCollectionsClients, JsonRequestBehavior.AllowGet);
                break;
            case "projectsMyWorkInProcessGrid":
                returnJsonResult = Json(projectData.myWorkInProcessClients, JsonRequestBehavior.AllowGet);
                break;
            case "burnMyLaborBurnRateGrid":
                returnJsonResult = Json(burnData.myLaborBurnRateClients, JsonRequestBehavior.AllowGet);
                break;
            case "burnMyLaborRevenueProjectionGrid":
                returnJsonResult = Json(burnData.myLaborRevenueProjectionClients, JsonRequestBehavior.AllowGet);
                break;
        }

        return returnJsonResult;
    }

但要做到这一点,我需要我的模型继承自Controller。这是不好的做法吗?我应该以其他方式这样做吗?

一些背景......其中每一个都是通过ajax调用向网页上的网格/表格提供数据:

$.getJSON('@Url.Action("Data", "PortfolioManager")' + '?gridName=burnMyLaborRevenueProjectionGrid', function (data) {

                    ConstructburnMyLaborRevenueProjectionGrid(data);
                    $('#burnMyLaborRevenueProjectionLoadingIndicator').hide();
                    numGridsLoaded = numGridsLoaded + 1;
                });

它的工作原理如下(继承自Controller),但感觉的东西......

0 个答案:

没有答案