使用Sitecore的TempData

时间:2015-12-29 19:34:18

标签: asp.net-mvc sitecore

我在第一次重定向时将TempData值访问回同一页面时遇到问题。检查时,TempData字典为空。 TempData应该能够持续第一个HTTP请求,为什么它会变回空?是否存在一些我缺少的特定于sitecore的内容?

[HttpPost]
    public ActionResult Update(InformationViewModel model)
    {
        if (ModelState.IsValid)
        {
            try
            {
                var Id = Session[SessionCurrentIdKey];

                var mailingAddress = new MailingAddress();
                var contactInformation = new ContactInformation();
                var operatingDetails = new OperatingDetails();

                Mapper.Map(model, mailingAddress);
                Mapper.Map(model, contactInformation);
                Mapper.Map(model, operatingDetails);

                WebApiHelper.Upload("MailingAddress", Id, mailingAddress);
                WebApiHelper.Upload("ContactInformation", Id, contactInformation);
                WebApiHelper.Upload("OperatingDetails", Id, operatingDetails);

                TempData["Message"] = "Successfully updated information.";
                TempData["Message-Class"] = "success";
            }
            catch (Exception e)
            {
                Log.Error("Error updating information", e, this);
                TempData["Message"] = "Could not update information.";
                TempData["Message-Class"] = "danger";
            }
        }
        else
        {
            var errors = GetErrorMessages(ModelState);

            TempData["Message"] = "The form values are not valid. Please fix the issues below.";
            TempData["Message"] += errors.ToString();
            TempData["Message-Class"] = "danger";
        }

        return new RedirectResult("~/Information");
    }

0 个答案:

没有答案