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


C# ViewDataDictionary.Add方法代码示例

本文整理汇总了C#中ViewDataDictionary.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ViewDataDictionary.Add方法的具体用法?C# ViewDataDictionary.Add怎么用?C# ViewDataDictionary.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ViewDataDictionary的用法示例。


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

示例1: OnAuthorization

        public override void OnAuthorization( AuthorizationContext filterContext )
        {
            if ( filterContext == null )
            {
                throw new ArgumentNullException( "filterContext" );
            }

            if ( AuthorizeCore( filterContext.HttpContext ) )
            {
                // ** IMPORTANT **
                // Since we're performing authorization at the action level, the authorization code runs
                // after the output caching module. In the worst case this could allow an authorized user
                // to cause the page to be cached, then an unauthorized user would later be served the
                // cached page. We work around this by telling proxies not to cache the sensitive page,
                // then we hook our custom authorization code into the caching mechanism so that we have
                // the final say on whether a page should be served from the cache.

                HttpCachePolicyBase cachePolicy = filterContext.HttpContext.Response.Cache;
                cachePolicy.SetProxyMaxAge( new TimeSpan( 0 ) );
                cachePolicy.AddValidationCallback( CacheValidateHandler, null /* data */);
            }
            else
            {
                // auth failed, redirect to not authorized page
                ViewDataDictionary viewData = new ViewDataDictionary();
                viewData.Add( "PageTitle", "Not Authorised" );
                viewData.Add( "Message", "Sorry, you do not have sufficient privileges for this operation." );

                filterContext.Result = new ViewResult { ViewName = "NotAuthorised", ViewData = viewData };
                //filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary( new { area = "", controller = "Home" } ) );
            }
        }
开发者ID:j3itchtits,项目名称:jumblist,代码行数:32,代码来源:CustomAuthorizationAttribute.cs

示例2: BuildViewData

 public void BuildViewData(ViewDataDictionary viewDataDictionary, Order order)
 {
     viewDataDictionary.Add("Origins", _originRepository.GetAllOrigins().Select(o => new { Name = o, Value = o }));
     viewDataDictionary.Add("Customer", order.Customer);
     viewDataDictionary.Add("PackageTypes", _packageTypeSelectListBuilder.BuildSelectList());
     viewDataDictionary.Add("Destinations", _destinationRepository.GetAllDestinations().Select(d => new { Name = d, Value = d }));
 }
开发者ID:turtlechalk,项目名称:ui-for-aspnet-mvc-examples,代码行数:7,代码来源:OrderViewDataBuilder.cs

示例3: OnException

        public override void OnException(ExceptionContext filterContext)
        {

            if (filterContext == null) throw new ArgumentNullException("filterContext");
            if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled) return;
            var exception = filterContext.Exception;
            if (new HttpException(null, exception).GetHttpCode() != 500) return;
            var controllerName = (string)filterContext.RouteData.Values["controller"];
            var actionName = (string)filterContext.RouteData.Values["action"];
            var model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
            ActionResult result;
            if (IsJson)
                result = new JsonResult { Data = new { error = filterContext.Exception.Message }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
            else {
                var dict = new ViewDataDictionary<HandleErrorInfo>(model);
                if (filterContext.Controller.ViewData.ContainsKey("KatushaUser")) dict.Add("KatushaUser", filterContext.Controller.ViewData["KatushaUser"]);
                if (filterContext.Controller.ViewData.ContainsKey("KatushaProfile")) dict.Add("KatushaProfile", filterContext.Controller.ViewData["KatushaProfile"]);
                dict.Add("HasLayout", HasLayout);
                result = new ViewResult { ViewName = ExceptionView, ViewData = dict, TempData = filterContext.Controller.TempData };
            }
            filterContext.Result = result;
            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.Clear();
            filterContext.HttpContext.Response.StatusCode = 500;
            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
        }
开发者ID:ramazanaktolu,项目名称:MS.Katusha,代码行数:26,代码来源:KatushaFilterAttribute.cs

示例4: WebBlocksLiveEdit

 /// <summary>
 /// Adds live edit to the web page
 /// Use: @Html.WebBlocksLiveEdit(1055, "Wysiwyg")
 /// </summary>
 /// <param name="html"></param>
 /// <param name="blocksRootNode">Root node id for the blocks</param>
 /// <param name="stylesheetId">The wysiwyg stylesheet for TinyMCE</param>
 /// <returns></returns>
 public static string WebBlocksLiveEdit(this HtmlHelper<RenderModel> html, int blocksRootNode, int stylesheetId)
 {
     ViewDataDictionary viewData = new ViewDataDictionary();
     viewData.Add("wbBlocksRootNode", blocksRootNode);
     viewData.Add("wbStylesheetId", stylesheetId);
     html.RenderPartial("LiveEditRender", null, viewData);
     return "";
 }
开发者ID:bowserm,项目名称:Mentor-Web-Blocks,代码行数:16,代码来源:HtmlWebBlocksLiveEdit.cs

示例5: DropDownListForCategories

        public static IHtmlContent DropDownListForCategories(this IHtmlHelper helper, string id, string name, List<Category> list, Guid selected)
        {
            ViewDataDictionary vdd = new ViewDataDictionary(helper.ViewContext.ViewData);
            vdd.Add("Selected", selected);
            vdd.Add("Id", id);
            vdd.Add("Name", name);

            return helper.Partial("HtmlHelper/CategoriesList", list, vdd);
        }
开发者ID:mrtryhard,项目名称:mytryhard,代码行数:9,代码来源:HtmlExtension.cs

示例6: Merge_View_Data_Retains_Destination_Values

        public void Merge_View_Data_Retains_Destination_Values()
        {
            var source = new ViewDataDictionary();
            var dest = new ViewDataDictionary();
            source.Add("Test1", "Test1");
            dest.Add("Test1", "MyValue");
            dest.Add("Test2", "Test2");

            dest.MergeViewDataFrom(source);

            Assert.AreEqual(2, dest.Count);
            Assert.AreEqual("MyValue", dest["Test1"]);
            Assert.AreEqual("Test2", dest["Test2"]);
        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:14,代码来源:ViewDataDictionaryExtensionTests.cs

示例7: OnAuthorization

        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }

            if (AuthorizeCore(filterContext.HttpContext))
            {
                SetCachePolicy(filterContext);
            }
            else if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                // auth failed, redirect to login page
                filterContext.Result = new HttpUnauthorizedResult();
            }
            else if (filterContext.HttpContext.User.IsInRole("SuperUser"))
            {
                // is authenticated and is in the SuperUser role
                SetCachePolicy(filterContext);
            }
            else
            {
                ViewDataDictionary viewData = new ViewDataDictionary();
                viewData.Add("Message", "You do not have sufficient privileges for this operation.");
                filterContext.Result = new ViewResult { MasterName = this.MasterName, ViewName = this.ViewName, ViewData = viewData };
            }
        }
开发者ID:bzure,项目名称:BCF,代码行数:28,代码来源:MasterEventAuthorizeAttribute.cs

示例8: OnAuthorization

 public void OnAuthorization(AuthorizationContext filterContext)
 {
     if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
     {
         filterContext.Result = new RedirectToRouteResult(
             new RouteValueDictionary
             {
                 { "action","Login"},
                 { "controller","Home"}
             }
             );
         //filterContext.Result = new HttpUnauthorizedResult();
     }
     else
     {
         ViewDataDictionary viewData = new ViewDataDictionary();
         viewData.Add("Message", "You do not have sufficient privileges for this operation.");
         filterContext.Result = new ViewResult
         {
             ViewData = viewData
         };
     }
     //else if (filterContext.HttpContext.User.IsInRole("admin"))
     //{
     //    filterContext.Result = new HttpUnauthorizedResult();
     //}
 }
开发者ID:rpaycin,项目名称:MVCAuthorize,代码行数:27,代码来源:CustomAuthorizationFilter.cs

示例9: SetControllerView

 /// <summary>
 /// 设置Controller ViewData
 /// </summary>
 /// <param name="controller"></param>
 /// <param name="Key"></param>
 /// <param name="Value"></param>
 public static ViewDataDictionary SetControllerView(this Controller controller,string Key,string Value)
 {
     //string Name = controller.GetControllerName();
     ViewDataDictionary vDict = new ViewDataDictionary();
     vDict.Add(Key, Value);
     return vDict;
 }
开发者ID:huaminglee,项目名称:hfoa,代码行数:13,代码来源:ControllerConfig.cs

示例10: View

        protected new virtual ContentResult View(string viewName, object model = null)
        {
            var controllerContext = this.ControllerContext;
            var result = ViewEngines.Engines.FindView(controllerContext, viewName, null);

            StringWriter output;
            using (output = new StringWriter())
            {
                var dictionary = new ViewDataDictionary(model);

                var dynamic = this.ViewBag as DynamicObject;

                if (dynamic != null)
                {
                    var members = dynamic.GetDynamicMemberNames().ToList();

                    foreach (string member in members)
                    {
                        var value = Versioned.CallByName(dynamic, member, CallType.Get);
                        dictionary.Add(member, value);
                    }
                }


                var viewContext = new ViewContext(controllerContext, result.View, dictionary,
                    controllerContext.Controller.TempData, output);
                result.View.Render(viewContext, output);
                result.ViewEngine.ReleaseView(controllerContext, result.View);
            }

            string html = CdnHelper.UseCdn(output.ToString());
            html = CustomJavascriptInjector.Inject(viewName, html);
            html = MinificationHelper.Minify(html);
            return this.Content(html, "text/html");
        }
开发者ID:frapid,项目名称:frapid,代码行数:35,代码来源:FrapidController.cs

示例11: EvalEvaluatesDictionaryThenModel

        public void EvalEvaluatesDictionaryThenModel() {
            var obj = new { Foo = "NotBar" };
            ViewDataDictionary vdd = new ViewDataDictionary(obj);
            vdd.Add("Foo", "Bar");

            Assert.AreEqual("Bar", vdd.Eval("Foo"));
        }
开发者ID:sanyaade-mobiledev,项目名称:ASP.NET-Mvc-2,代码行数:7,代码来源:ViewDataDictionaryTest.cs

示例12: RenderPartialWithData

 /// <summary>
 /// Loads the supplied object to the view data dictionary for use by other partials
 /// </summary>
 public static void RenderPartialWithData(this HtmlHelper htmlHelper, string partialName, string key, object objectToLoad, ViewDataDictionary viewDataDictionary)
 {
     if (!viewDataDictionary.ContainsKey(key))
     {
         viewDataDictionary.Add(key, objectToLoad);
     }
     htmlHelper.RenderPartial(partialName);
 }
开发者ID:cerikpete,项目名称:MVCommand,代码行数:11,代码来源:HtmlExtensions.cs

示例13: CarregarDadosUsuario

        public static void CarregarDadosUsuario(ViewDataDictionary viewData)
        {
            if (viewData.ContainsKey("logado"))
                viewData["logado"] = viewData["logado"];
            else
                viewData.Add("logado", false);

            if (viewData.ContainsKey("tipoUsuario"))
                viewData["tipoUsuario"] = viewData["tipoUsuario"];
            else
                viewData.Add("tipoUsuario", "");

            if (viewData.ContainsKey("erroLogin"))
                viewData["erroLogin"] = viewData["erroLogin"];
            else
                viewData.Add("erroLogin", "");
        }
开发者ID:BernardoMorais,项目名称:LivrariaTDD,代码行数:17,代码来源:Helpers.cs

示例14: ShouldHandleProxiedObjectsByType

        public void ShouldHandleProxiedObjectsByType()
        {
            var mailMessageStub = MockRepository.GenerateStub<MailMessage>();
            var viewData = new ViewDataDictionary();
            viewData.Add(mailMessageStub);
            var message = viewData.Get<MailMessage>();

            Assert.That(message, Is.EqualTo(mailMessageStub));
        }
开发者ID:JonKruger,项目名称:MvcContrib,代码行数:9,代码来源:ViewDataExtensionsForViewDataTester.cs

示例15: ShouldGetObjectBasedOnType

        public void ShouldGetObjectBasedOnType()
        {
            var url = new Url("/1");
            var identity = new GenericIdentity("name");

            var viewData = new ViewDataDictionary();
            viewData.Add(identity).Add(url);

            viewData.Get(typeof(MailMessage));
        }
开发者ID:JonKruger,项目名称:MvcContrib,代码行数:10,代码来源:ViewDataExtensionsForViewDataTester.cs


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