当前位置: 首页>>代码示例>>C#>>正文


C# TempDataDictionary类代码示例

本文整理汇总了C#中TempDataDictionary的典型用法代码示例。如果您正苦于以下问题:C# TempDataDictionary类的具体用法?C# TempDataDictionary怎么用?C# TempDataDictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TempDataDictionary类属于命名空间,在下文中一共展示了TempDataDictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderPartialToString

        public static string RenderPartialToString(this Controller controller, string partialView, ViewDataDictionary viewData, TempDataDictionary tempData)
        {
            ControllerContext controllerContext = controller.ControllerContext;
            var viewEngines = ViewEngines.Engines;
            var viewEngineResult = viewEngines.FindPartialView(controllerContext, partialView + ".js");

            ViewContext viewContext = new ViewContext(controllerContext, viewEngineResult.View, viewData,
                                                      tempData);

            var response = viewContext.HttpContext.Response;
            response.Flush();
            var oldFilter = response.Filter;
            Stream filter = null;
            try
            {
                filter = new MemoryStream();
                response.Filter = filter;
                viewContext.View.Render(viewContext, viewContext.HttpContext.Response.Output);
                response.Flush();
                filter.Position = 0;
                var reader = new StreamReader(filter, response.ContentEncoding);
                return reader.ReadToEnd();
            }
            finally
            {
                if (filter != null)
                {
                    filter.Dispose();
                }
                response.Filter = oldFilter;
            }
        }
开发者ID:sesquiv,项目名称:siacvu,代码行数:32,代码来源:PartialViewExtensions.cs

示例2: CopyTempDataToModelState

        private void CopyTempDataToModelState(ModelStateDictionary modelState, TempDataDictionary tempData)
        {
            if (!tempData.ContainsKey(TempDataKey)) return;

            var fromTempData = tempData[TempDataKey] as ModelStateDictionary;
            if (fromTempData == null) return;

            foreach (var pair in fromTempData)
            {
                if (modelState.ContainsKey(pair.Key))
                {
                    modelState[pair.Key].Value = pair.Value.Value;

                    foreach (var error in pair.Value.Errors)
                    {
                        if (!modelState[pair.Key].Errors.Contains(error))
                            modelState[pair.Key].Errors.Add(error);
                    }
                }
                else
                {
                    modelState.Add(pair.Key, pair.Value);
                }
            }
        }
开发者ID:kenwarner,项目名称:scrilla,代码行数:25,代码来源:Attributes.cs

示例3: CopyTempDataToModelState

        private void CopyTempDataToModelState(ModelStateDictionary modelState,
                                              TempDataDictionary tempData)
        {
            if (!tempData.ContainsKey(TempDataKey))
            {
                return;
            }

            ModelStateDictionary fromTempData = tempData[TempDataKey]
                                                    as ModelStateDictionary;
            if (fromTempData == null)
            {
                return;
            }

            foreach (KeyValuePair<string, ModelState> pair in fromTempData)
            {
                if (modelState.ContainsKey(pair.Key))
                {
                    modelState[pair.Key].Value = pair.Value.Value;

                    foreach (ModelError error in pair.Value.Errors)
                    {
                        modelState[pair.Key].Errors.Add(error);
                    }
                }
                else
                {
                    modelState.Add(pair.Key, pair.Value);
                }
            }
        }
开发者ID:stiano,项目名称:ShopperDopper,代码行数:32,代码来源:ModelStateToTempAttribute.cs

示例4: PropertiesAreSet

        public void PropertiesAreSet()
        {
            // Arrange
            var mockControllerContext = new Mock<ControllerContext>();
            mockControllerContext.Setup(o => o.HttpContext.Items).Returns(new Hashtable());
            var view = new Mock<IView>().Object;
            var viewData = new ViewDataDictionary();
            var tempData = new TempDataDictionary();
            var writer = new StringWriter();

            // Act
            ViewContext viewContext = new ViewContext(mockControllerContext.Object, view, viewData, tempData, writer);

            // Setting FormContext to null will return the default one later
            viewContext.FormContext = null;

            // Assert
            Assert.Equal(view, viewContext.View);
            Assert.Equal(viewData, viewContext.ViewData);
            Assert.Equal(tempData, viewContext.TempData);
            Assert.Equal(writer, viewContext.Writer);
            Assert.False(viewContext.UnobtrusiveJavaScriptEnabled); // Unobtrusive JavaScript should be off by default
            Assert.NotNull(viewContext.FormContext); // We get the default FormContext
            Assert.Equal("span", viewContext.ValidationSummaryMessageElement); // gen a <span/> by default
            Assert.Equal("span", viewContext.ValidationMessageElement); // gen a <span/> by default
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:26,代码来源:ViewContextTest.cs

示例5: ViewContext

        public ViewContext(ControllerContext controllerContext, IView view, ViewDataDictionary viewData, TempDataDictionary tempData)
            : base(controllerContext) {
            if (controllerContext == null) {
                throw new ArgumentNullException("controllerContext");
            }
            if (view == null) {
                throw new ArgumentNullException("view");
            }
            if (viewData == null) {
                throw new ArgumentNullException("viewData");
            }
            if (tempData == null) {
                throw new ArgumentNullException("tempData");
            }

            View = view;
            ViewData = viewData;
            TempData = tempData;

            // propagate FormContext, e.g. inside a template
            ViewContext originalViewContext = controllerContext as ViewContext;
            if (originalViewContext != null) {
                FormContext = originalViewContext.FormContext;
            }
        }
开发者ID:Marceli,项目名称:JQueryGridTest,代码行数:25,代码来源:ViewContext.cs

示例6: SetDisplayModeType

        public void SetDisplayModeType(ViewDataDictionary viewData, TempDataDictionary tempData, string displayMode, Type displayModeType)
        {
            var sut = new ViewModelSummary(viewData, tempData, typeof(ViewModelSummary), true, displayMode, displayModeType);

            Assert.Equal(displayModeType, sut.DisplayModeType);
            Assert.True(sut.HasDisplayMode);
        }
开发者ID:GitObjects,项目名称:Glimpse,代码行数:7,代码来源:ViewModelSummaryShould.cs

示例7: Error

        public ActionResult Error( TempDataDictionary data )
        {
            List<ModelError> errorList = TempData["errors"] as List<ModelError>;

            ViewBag.Title = "Something went wrong";
            return View( errorList );
        }
开发者ID:ylyubimov,项目名称:Portal,代码行数:7,代码来源:HomeController.cs

示例8: AddParameterValuesFromExpressionToTempData

        // Copied this method from Microsoft.Web.Mvc.dll (MVC Futures)...
        // Microsoft.Web.Mvc.Internal.ExpresisonHelper.AddParameterValuesFromExpressionToDictionary().
        // The only change I made is saving the parameter values to TempData instead
        // of a RouteValueDictionary.
        private IDictionary<string, object> AddParameterValuesFromExpressionToTempData(TempDataDictionary tempData,
                                                                                       MethodCallExpression call)
        {
            ParameterInfo[] parameters = call.Method.GetParameters();
            var parsedParameters = new Dictionary<string, object>();

            if(parameters.Length > 0)
            {
                for(int i = 0; i < parameters.Length; i++)
                {
                    Expression expression = call.Arguments[i];
                    object obj2 = null;
                    ConstantExpression expression2 = expression as ConstantExpression;
                    if(expression2 != null)
                    {
                        obj2 = expression2.Value;
                    }
                    else
                    {
                        Expression<Func<object>> expression3 =
                            Expression.Lambda<Func<object>>(Expression.Convert(expression, typeof(object)),
                                                            new ParameterExpression[0]);
                        obj2 = expression3.Compile()();
                    }

                    tempData[RedirectParameterPrefix + parameters[i].Name] = obj2;
                    parsedParameters.Add(parameters[i].Name, obj2);
                }
            }

            return parsedParameters;
        }
开发者ID:hillsoul,项目名称:MvcContrib,代码行数:36,代码来源:PassParametersDuringRedirectAttribute.cs

示例9: GetViewHtml

        public static string GetViewHtml(string partialViewName, object model)
        {
            //Fake a context
            var context = new ControllerContext();
            context.RouteData = HttpContext.Current.Request.RequestContext.RouteData;
            context.RequestContext = HttpContext.Current.Request.RequestContext;

            ViewEngineResult result = ViewEngines.Engines.FindPartialView(context, partialViewName);

            // Try a regular view if partial not found
            if (result.View == null)
            {
                result = ViewEngines.Engines.FindView(context, partialViewName, "_layout");
            }

            var viewData = new ViewDataDictionary(model);
            var tempData = new TempDataDictionary();

            if (result.View != null)
            {
                var sb = new StringBuilder();
                using (var sw = new StringWriter(sb))
                {
                    using (var output = new HtmlTextWriter(sw))
                    {
                        var viewContext = new ViewContext(context, result.View, viewData, tempData, output);
                        result.View.Render(viewContext, output);
                    }
                }

                return sb.ToString();
            }
            return String.Empty;
        }
开发者ID:marciocamello,项目名称:dirigo-edge,代码行数:34,代码来源:DynamicModules.cs

示例10: GetControllerContext

 private static ControllerContext GetControllerContext(TempDataDictionary tempData) {
     return new ControllerContext() {
         Controller = new EmptyController() {
             TempData = tempData
         }
     };
 }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:7,代码来源:TempDataValueProviderFactoryTest.cs

示例11: GuardClauses

        public void GuardClauses()
        {
            // Arrange
            var controllerContext = new Mock<ControllerContext>().Object;
            var view = new Mock<IView>().Object;
            var viewData = new ViewDataDictionary();
            var tempData = new TempDataDictionary();
            var writer = new StringWriter();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                () => new ViewContext(null, view, viewData, tempData, writer),
                "controllerContext"
                );
            Assert.ThrowsArgumentNull(
                () => new ViewContext(controllerContext, null, viewData, tempData, writer),
                "view"
                );
            Assert.ThrowsArgumentNull(
                () => new ViewContext(controllerContext, view, null, tempData, writer),
                "viewData"
                );
            Assert.ThrowsArgumentNull(
                () => new ViewContext(controllerContext, view, viewData, null, writer),
                "tempData"
                );
            Assert.ThrowsArgumentNull(
                () => new ViewContext(controllerContext, view, viewData, tempData, null),
                "writer"
                );
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:31,代码来源:ViewContextTest.cs

示例12: SetModelType

 public void SetModelType(ViewDataDictionary viewData, TempDataDictionary tempData, string displayMode, Type displayModeType)
 {
     var sut = new ViewModelSummary(viewData, tempData, typeof(ViewModelSummary), true, displayMode, displayModeType);
      
     Assert.Equal(true, sut.IsValid);
     Assert.Equal(typeof(ViewModelSummary), sut.ModelType);
 }
开发者ID:GitObjects,项目名称:Glimpse,代码行数:7,代码来源:ViewModelSummaryShould.cs

示例13: ToString

        /// <summary>
        /// Renders a partial view to a string in the specified context.
        /// </summary>
        /// <param name="partialViewContext">The partial view context.</param>
        /// <param name="viewModel">The view model.</param>
        /// <param name="cookies">Any cookies that were captures as part of the response.</param>
        /// <returns>The view rendered as a string.</returns>
        public static string ToString(PartialViewContext partialViewContext, object viewModel, out HttpCookieCollection cookies)
        {
            string viewName = partialViewContext.ViewName;

            using (var writer = new StringWriter())
            {
                var httpRequest = new HttpRequest("", "http://www.example.com", "");
                var httpResponse = new HttpResponse(writer);

                // There are still dependencies on HttpContext.Currrent in the ASP.NET (MVC) framework, eg., AntiForgeryRequestToken (as of ASP.NET MVC 4).
                var httpContext = new HttpContext(httpRequest, httpResponse) { User = partialViewContext.User };
                System.Web.HttpContext.Current = httpContext;

                var controllerContext = CreateControllerContext(httpContext);

                var viewEngineResult = ViewEngines.Engines.FindPartialView(controllerContext, viewName);
                if (viewEngineResult == null)
                {
                    string message = "The partial view was not found.";
                    throw new ArgumentException(message, viewName);
                }

                var view = viewEngineResult.View;
                if (view == null)
                {
                    var locations = new StringBuilder();
                    foreach (string searchedLocation in viewEngineResult.SearchedLocations)
                    {
                        locations.AppendLine();
                        locations.Append(searchedLocation);
                    }

                    throw new ArgumentException("The partial view was not found. The following locations were searched: " + locations, viewName);
                }

                try
                {
                    var viewData = new ViewDataDictionary(viewModel);
                    var tempData = new TempDataDictionary();

                    var viewContext = new ViewContextStub(controllerContext, view, viewData, tempData, writer)
                    {
                        ClientValidationEnabled = partialViewContext.ClientValidationEnabled,
                        UnobtrusiveJavaScriptEnabled = partialViewContext.UnobtrusiveJavaScriptEnabled
                    };

                    view.Render(viewContext, httpResponse.Output);
                    cookies = controllerContext.HttpContext.Response.Cookies;

                    httpResponse.Flush();
                }
                finally
                {
                    viewEngineResult.ViewEngine.ReleaseView(controllerContext, view);
                }

                return writer.ToString();
            }
        }
开发者ID:marcusoftnet,项目名称:crowbar,代码行数:66,代码来源:CrowbarController.cs

示例14: Keep_DoesNotThrowException_WhenDataIsNotLoaded

        public void Keep_DoesNotThrowException_WhenDataIsNotLoaded()
        {
            // Arrange
            var tempData = new TempDataDictionary(GetHttpContextAccessor(), new SessionStateTempDataProvider());

            // Act & Assert
            tempData.Keep();
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:8,代码来源:TempDataDictionaryTest.cs

示例15: PartialViewHtml

        protected string PartialViewHtml(string partialViewName, object model, ViewDataDictionary viewData)
        {
            var data = new ViewDataDictionary(viewData) {Model = model};

            var tempData = new TempDataDictionary();

            return RenderPartialToString(this.ControllerContext, partialViewName, data, tempData);
        }
开发者ID:supermuk,项目名称:iudico,代码行数:8,代码来源:CourseBaseController.cs


注:本文中的TempDataDictionary类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。