调用Controller方法时出现问题

时间:2016-07-12 09:43:20

标签: asp.net-mvc asp.net-mvc-3

我有两个名为FormController和CorticonResponseController的控制器。

的FormController:

[HttpPost]

公共ActionResult索引(FormCollection formCollection)         {

        Session["CorticonServiceEndpoint"] = this.CorticonServiceEndpoint;
        Session["CorticonServiceName"] = this.CorticonServiceName;
        Session["CorticonServiceMajorVersion"] = this.CorticonServiceMajorVersion;
        Session["CorticonServiceMinorVersion"] = this.CorticonServiceMinorVersion;

        Session["payLoad"] = “Test”;

        return RedirectToAction("CorticonIndex ", “CorticonResponseController”);
    }

CorticonResponseController:

    public ActionResult CorticonIndex()
    {
        string payLoad = (string)Session["payLoad"];

        string CorticonServiceEndpoint = (string)Session["CorticonServiceEndpoint"];
        string CorticonServiceName = (string)Session["CorticonServiceName"];
        string CorticonServiceMajorVersion = (string)Session["CorticonServiceMajorVersion"];
        string CorticonServiceMinorVersion = (string)Session["CorticonServiceMinorVersion"];

        var viewModel = this.Model.GetViewModel(payLoad);


        return View ("Default", viewModel);
    }

在这里,我从FormController向CorticonResponseController发送了一些信息。在CorticonResponseController中,我进行了一些计算并使用模型返回视图。 因此,网址从http://localhost:35583/banking/open-an-account更改为http://localhost:35583/banking/open-an-account/CorticonIdex

但是,我不想更改URL,因此我修改了我的代码,如下所示。

CorticonResponseController:

   public void CorticonIndex()
    {
        string payLoad = (string)Session["payLoad"];

        string CorticonServiceEndpoint = (string)Session["CorticonServiceEndpoint"];
        string CorticonServiceName = (string)Session["CorticonServiceName"];
        string CorticonServiceMajorVersion = (string)Session["CorticonServiceMajorVersion"];
        string CorticonServiceMinorVersion = (string)Session["CorticonServiceMinorVersion"];

        var viewModel = this.Model.GetViewModel(payLoad);
        TempData["ResponseController"] = viewModel;
    }

的FormController:

    [HttpPost]

    public ActionResult Index(FormCollection formCollection)
    {

        Session["CorticonServiceEndpoint"] = this.CorticonServiceEndpoint;
        Session["CorticonServiceName"] = this.CorticonServiceName;
        Session["CorticonServiceMajorVersion"] = this.CorticonServiceMajorVersion;
        Session["CorticonServiceMinorVersion"] = this.CorticonServiceMinorVersion;

        Session["payLoad"] = “Test”;

        CorticonResponseController obj = new CorticonResponseController();
        obj.CorticonIndex();


        CorticonResponseModel viewModel = (CorticonResponseModel)TempData["ResponseController"];

        string controllerName = DecisionServiceProgram.GetResponseWidgetName();

        return View("Default", viewModel);
    }

在这里,在我的FormController中,我正在调用CorticonResponseController方法并使用TempData获取CorticonResponseModel数据,然后返回视图。

执行控制器时我遇到了问题。

有人可以帮我解决问题吗?

0 个答案:

没有答案