• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Mvc.ControllerBase类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: ToPaging

        public static void ToPaging(int pageIndex, int dataCount, ControllerBase controller, int pageSize = 20)
        {
            int pagesCount = 1;
            int pageStartIndex = 1;
            int pageEndIndex = 0;
            controller.ViewBag.PageNowIndex = pageIndex;
            controller.ViewBag.PageSize = pageSize;
            controller.ViewBag.PagesCount = pagesCount = pageEndIndex = int.Parse(Math.Ceiling((double)dataCount / pageSize).ToString());

            if (pagesCount > 9)
            {
                //最多显示9个页码
                if (pageIndex > 5)
                {
                    pageStartIndex = pageIndex - 4;
                    if (pagesCount - pageIndex > 4)
                        pageEndIndex = pageIndex + 4;
                }
                else
                    pageEndIndex = 9;
            }

            controller.ViewBag.PageStartIndex = pageStartIndex;
            controller.ViewBag.PageEndIndex = pageEndIndex;
        }
开发者ID:jingwang109,项目名称:zsfproject,代码行数:25,代码来源:Paging.cs


示例2: Dynamic

        protected virtual ActionResult Dynamic(ControllerBase controller, string viewName, object model, Func<ControllerBase, Dictionary<string, object>, string, object, object> json)
        {
            var propertyBag = new Dictionary<string, object>();
            
            if (model != null)
            {
                List<JsonField> properties;
                var cacheKey = model.GetType().FullName;

                if (!_propertyCache.TryGet(cacheKey, out properties))
                {
                    properties = new List<JsonField>();
                    properties.AddRange(model.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
                        .Where(property => GetCustomAttribute(property, typeof(JsonPropertyAttribute)) != null)
                        .Select(property => new JsonField(property, (JsonPropertyAttribute)GetCustomAttribute(property, typeof(JsonPropertyAttribute))))
                        .ToList());
                    properties.AddRange(model.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)
                        .Where(field => GetCustomAttribute(field, typeof(JsonPropertyAttribute)) != null)
                        .Select(field => new JsonField(field, (JsonPropertyAttribute)GetCustomAttribute(field, typeof(JsonPropertyAttribute))))
                        .ToList());

                    _propertyCache.Add(cacheKey, properties);
                }

                properties.ForEach(property => propertyBag.Add(property.Name, property.GetValue(model)));
            }

            return controller.AsDynamic().Json(json(controller, propertyBag, viewName, model), JsonRequestBehavior.AllowGet);
        }
开发者ID:grbbod,项目名称:drconnect-jungo,代码行数:29,代码来源:DynamicActionResultAttribute.cs


示例3: WriteForgeryToken

        private static void WriteForgeryToken(ControllerBase controller)
        {
            string cookieToken, formToken;
            var context = controller.ControllerContext.HttpContext;

            var oldCookie = context.Request.Cookies[AntiForgeryConfig.CookieName];
            var oldCookieToken = oldCookie != null ? oldCookie.Value : null;

            AntiForgery.GetTokens(oldCookieToken, out cookieToken, out formToken);
            context.Items[FlushedAntiForgeryTokenKey] = formToken;

            if (AntiForgeryConfig.RequireSsl && !context.Request.IsSecureConnection)
            {
                throw new InvalidOperationException("WebPageResources.AntiForgeryWorker_RequireSSL");
                    //TODO: Find string message
            }

            var response = context.Response;

            if (!string.IsNullOrEmpty(cookieToken))
            {
                response.Cookies.Set(new HttpCookie(AntiForgeryConfig.CookieName, cookieToken) { HttpOnly = true });
            }

            if (!AntiForgeryConfig.SuppressXFrameOptionsHeader)
            {
                // Adding X-Frame-Options header to prevent ClickJacking. See
                // http://tools.ietf.org/html/draft-ietf-websec-x-frame-options-10
                // for more information.
                response.AddHeader("X-Frame-Options", "SAMEORIGIN");
            }
        }
开发者ID:nikmd23,项目名称:CourtesyFlush,代码行数:32,代码来源:ContollerBaseExtension.cs


示例4: GetModelValidator

 private static ModelValidator GetModelValidator(this object model, ControllerBase controller)
 {
     return ModelValidator.GetModelValidator(
         ModelMetadataProviders.Current.GetMetadataForType(() => model, model.GetType()),
         controller.ControllerContext
         );
 }
开发者ID:DerAlbertCom,项目名称:FluentMetadata,代码行数:7,代码来源:ControllerValidationExtensions.cs


示例5: GetActionDescriptor

 private static ActionDescriptor GetActionDescriptor(ControllerBase controller, RouteData routeData)
 {
     var controllerDescriptor = new ReflectedControllerDescriptor(controller.GetType());
     var actionName = routeData.GetRequiredString("action");
     var actionDescriptor = controllerDescriptor.FindAction(controller.ControllerContext, actionName);
     return actionDescriptor;
 }
开发者ID:sandermvanvliet,项目名称:Xania.AspNet,代码行数:7,代码来源:HttpControllerAction.cs


示例6: Resource

        /// <summary>
        /// Get the label with the specified key from the resource files.
        /// </summary>
        /// <param name="controller">Controller that requests the resource.</param>
        /// <param name="key">The key.</param>
        /// <param name="fallbackToKey">If true then if a resource is not found with the specified key the key is returned.</param>
        private static string Resource(ControllerBase controller, RouteData routeData, string key, bool fallbackToKey)
        {
            var resClass = LocalizationHelpers.FindResourceStringClassType(controller.GetType());

            var widgetName = routeData != null ? routeData.Values["widgetName"] as string : null;
            if (!string.IsNullOrEmpty(widgetName))
            {
                var widget = FrontendManager.ControllerFactory.ResolveControllerType(widgetName);
                if (widget != null)
                {
                    var widgetResClass = LocalizationHelpers.FindResourceStringClassType(widget);
                    string res;
                    if (widgetResClass != null && Res.TryGet(widgetResClass.Name, key, out res))
                    {
                        return res;
                    }
                }
            }

            string result;
            if (Res.TryGet(resClass.Name, key, out result))
            {
                return result;
            }

            if (fallbackToKey)
            {
                return key;
            }
            
            return "#ResourceNotFound: {0}, {1}#".Arrange(resClass.Name, key);
        }
开发者ID:jeffpignataro,项目名称:feather,代码行数:38,代码来源:LocalizationHelpers.cs


示例7: TaxonomyUrlParamsMapper

 /// <summary>
 /// Initializes a new instance of the <see cref="TaxonomyUrlParamsMapper" /> class.
 /// </summary>
 /// <param name="controller">The controller.</param>
 /// <param name="taxonUrlEvaluator">The taxon URL evaluator.</param>
 /// <param name="actionName">Name of the action.</param>
 public TaxonomyUrlParamsMapper(ControllerBase controller, TaxonUrlMapper taxonUrlEvaluator, string actionName = TaxonomyUrlParamsMapper.DefaultActionName)
     : base(controller)
 {
     this.actionName = actionName;
     this.taxonUrlEvaluator = taxonUrlEvaluator;
     this.actionMethod = controller.GetType().GetMethod(this.actionName, BindingFlags.Instance | BindingFlags.Public);
 }
开发者ID:RifasRazick,项目名称:feather,代码行数:13,代码来源:TaxonomyUrlParamsMapper.cs


示例8: CreateMockControllerContext

 public static ControllerContext CreateMockControllerContext(ControllerBase controller)
 {
     var mockHttpContext = CreateMockHttpContext();
       var controllerContext = new ControllerContext(mockHttpContext, new RouteData(), controller);
       controller.ControllerContext = controllerContext;
       return controllerContext;
 }
开发者ID:pwideman,项目名称:ClubPool,代码行数:7,代码来源:ControllerHelper.cs


示例9: AppendAlert

        /// <summary>
        /// Sets the alert for the mvc view to render. Rendered by Html.RenderAlertMessages().
        /// </summary>
        /// <param name="controllerBase">The MVC controller from which this call is being made.</param>
        /// <param name="alert">The populated alert to show to the user.</param>
        /// <exception cref="ArgumentNullException">If either argument is null.</exception>
        public static void AppendAlert(ControllerBase controllerBase, AlertDetail alert)
        {
            if (controllerBase == null)
                throw new ArgumentNullException("controllerBase");
            if (alert == null)
                throw new ArgumentNullException("alert");

            Queue<AlertDetail> queue;

            // Get the queue
            if (alert.EnableCrossView)
                queue = controllerBase.TempData["CouncilSoft.BootstrapAlerts"] as Queue<AlertDetail>;
            else
                queue = controllerBase.ViewData["CouncilSoft.BootstrapAlerts"] as Queue<AlertDetail>;

            // Or create the queue
            if (queue == null)
                queue = new Queue<AlertDetail>();

            // Enqueue the item
            queue.Enqueue(alert);

            // Persist the updated queue.
            if (alert.EnableCrossView)
                controllerBase.TempData["CouncilSoft.BootstrapAlerts"] = queue;
            else
                controllerBase.ViewData["CouncilSoft.BootstrapAlerts"] = queue;
        }
开发者ID:theolymp,项目名称:CouncilSoft.BootstrapAlert,代码行数:34,代码来源:AlertManager.cs


示例10: CopyControllerData

        /// <summary>
        /// Ensure TempData and ViewData is copied across
        /// </summary>
        private static void CopyControllerData(ControllerContext context, ControllerBase controller)
        {
            foreach (var d in context.Controller.ViewData)
                controller.ViewData[d.Key] = d.Value;

            controller.TempData = context.Controller.TempData;
        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:10,代码来源:UmbracoPageResult.cs


示例11: Hydrate

        public void Hydrate(ControllerBase controller)
        {
            if (_model == null)
                return;

            controller.ViewData.Model = _model;
        }
开发者ID:khalidabuhakmeh,项目名称:PerfMatters.Flush,代码行数:7,代码来源:IHydrator.cs


示例12: CreateControllerContext

		public static ControllerContext CreateControllerContext (ControllerBase controller, Dictionary<string, string> formValues, 
									 HttpCookieCollection requestCookies, IDictionary<string, string> routeData)
		{
			HttpContextBase httpContext = CreateHttpContext ();

			if (formValues != null) {
				foreach (string key in formValues.Keys)
					httpContext.Request.Form.Add (key, formValues[key]);
			}

			if (requestCookies != null) {
				foreach (string key in requestCookies.Keys)
					httpContext.Request.Cookies.Add (requestCookies[key]);
			}

			RouteData route = new RouteData ();
			route.Values.Add ("controller", controller.GetType ().Name);

			if (routeData != null) {
				foreach (var valuePair in routeData)
					route.Values.Add (valuePair.Key, valuePair.Value);
			}

			return new ControllerContext (new RequestContext (httpContext, route), controller);
		}
开发者ID:ivanz,项目名称:IvanZ.Mvc.LocalizableViews,代码行数:25,代码来源:MockHelper.cs


示例13: FakeControllerContext

 public FakeControllerContext(
     ControllerBase controller,
     IPrincipal principal
     )
     : base(new FakeHttpContext(principal, null, null, null, null), new RouteData(), controller)
 {
 }
开发者ID:BrandFox,项目名称:beavers-encounter,代码行数:7,代码来源:FakeControllerContext.cs


示例14: GetFlashMessages

 private static IDictionary<string, MvcHtmlString> GetFlashMessages(ControllerBase controller, string sessionKey)
 {
     sessionKey = "Flash." + sessionKey;
     return (controller.TempData[sessionKey] != null
                 ? (IDictionary<string, MvcHtmlString>)controller.TempData[sessionKey]
                 : new Dictionary<string, MvcHtmlString>());
 }
开发者ID:briansalato,项目名称:Irving,代码行数:7,代码来源:FlashHelper.cs


示例15: EnsureControllerContext

 private static void EnsureControllerContext(ControllerBase controller)
 {
     if (controller.ControllerContext==null)
     {
         controller.ControllerContext=new ControllerContext();
     }
 }
开发者ID:DerAlbertCom,项目名称:FluentMetadata,代码行数:7,代码来源:ControllerValidationExtensions.cs


示例16: OnQueryStatusCallback

        private static NavigationHubStatus OnQueryStatusCallback(
            NavigationHub hub,
            TfsWebContext tfsWebContext,
            ControllerBase controller)
        {
            if (tfsWebContext == null)
            {
                return null;
            }

            // this gets the appropriate route name for the NavigationContextLevel of the current context.
            var controllerActionRouteName = TfsRouteHelpers.GetControllerActionRouteName(tfsWebContext);

            // builds the ActionLink using that NavigationContextLevel appropriate route
            var actionLink = tfsWebContext.Url.RouteUrl(
                controllerActionRouteName,
                "index",
                "customhome",
                new { routeArea = string.Empty });

            return new NavigationHubStatus(hub)
            {
                HubGroup = WellKnownHubGroup.Custom,
                HubGroupDisplayText = CustomAreaName,
                DisplayText = "Echo",
                CommandId = "Custom.CustomHome.Index",
                Order = 100,
                ActionLink = actionLink,
                ActionArguments = new { message = "None" },
                Selected = controller is CustomHomeController
            };
        }
开发者ID:antonalex,项目名称:Demos,代码行数:32,代码来源:CustomAreaRegistration.cs


示例17: darErroresValidacion

 public static void darErroresValidacion(ModelStateDictionary errores, ControllerBase controller)
 {
     var encontrados = new Dictionary<string,string>();
     var propiedades = errores.Keys.ToList();
     var errs = new List<string>();
     foreach (var item in errores.Values)
     {
         foreach (var e in item.Errors)
         {
             errs.Add(e.ErrorMessage);
         }
     }
     for (int i = 0; i <propiedades.Count; i++)
     {
         var prop = propiedades[i];
         string mensaje = string.Empty;
         try
         {
             mensaje = errs[i];
         }
         catch (Exception)
         {
             mensaje = "";
         }
         encontrados.Add(prop,mensaje);
     }
     controller.TempData["errores"] = encontrados;
 }
开发者ID:periface,项目名称:eCommerce,代码行数:28,代码来源:ServicioDeMensajes.cs


示例18: ShapePartialResult

 public ShapePartialResult(ControllerBase controller, dynamic shape)
 {
     ViewData = controller.ViewData;
     TempData = controller.TempData;
     ViewData.Model = shape;
     ViewName = "ShapeResult/DisplayPartial";
 }
开发者ID:gokhandisikara,项目名称:Coevery-Framework,代码行数:7,代码来源:ShapeResult.cs


示例19: SetController

 public void SetController(ControllerBase cntrl)
 {
     if (controller != null && controller.Equals(cntrl))
     {
         return;
     }
     controller = cntrl;
 }
开发者ID:antgerasim,项目名称:RealWorldMvc,代码行数:8,代码来源:ControllerContextHost.cs


示例20: GetModel

 /// <summary>
 /// Abstract method implementation to get the object in ViewData.Model
 /// </summary>
 /// <param name="controller">The controller object</param>
 /// <returns>The ViewData.Model object</returns>
 protected override object GetModel(ControllerBase controller)
 {
     object model = controller.ViewData.Model;
     if (null != model && model.GetType() == ModelType)
     {
         return model;
     }
     return null;
 }
开发者ID:triggerfish,项目名称:Common,代码行数:14,代码来源:ExportModelAttribute.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Mvc.ControllerBuilder类代码示例发布时间:2022-05-26
下一篇:
C# Mvc.ContentResult类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap