zoukankan      html  css  js  c++  java
  • 如何为asp.net mvc的action上统一加viewbag

    1、在项目中存在一些情况,需要为action加一些viewbag属性增强可维护性。

    [TitleFooterAttribute]
            // GET: yewulingyu
            public ActionResult Index()
            {
                int toal = 0;
                List<GongSiYeWu> list = new BLL_GongSiYewu().Search(-1, -1, out toal, null);
                return View(list);
            }

    然后我们看 TitleFooterAttribute的定义

      /// <summary>
        /// 为ViewBag添加默认参数
        /// </summary>
        public class TitleFooterAttribute : FilterAttribute, IResultFilter
        {
            public void OnResultExecuted(ResultExecutedContext filterContext)
            {
            }
    
            public void OnResultExecuting(ResultExecutingContext filterContext)
            {
                BLL_GongsiInfo bll = new BLL_GongsiInfo();
                GongsiInfo info = bll.GetSingle(Guid.Parse(ConfigurationManager.AppSettings["GongsiID"]));
                filterContext.Controller.ViewBag.GongsiFooter = info.GongsiFooter;
                filterContext.Controller.ViewBag.GongsiName = info.GongsiName;
                filterContext.Controller.ViewBag.GongsiSearchDes = info.GongsiSearchDes;
                filterContext.Controller.ViewBag.GongsiSearchkey = info.GongsiSearchkey;
                filterContext.Controller.ViewBag.GongsiCultrue = info.GongsiCultrue;
    
                filterContext.Controller.ViewBag.GongsiShortName = info.GongsiShortName;
                filterContext.Controller.ViewBag.GongsiLogo = info.GongsiLogo;
            }
        }
  • 相关阅读:
    爬取B站up主相册原图
    爬MEIZITU网站上的图片
    mpvue
    修改Tomcat控制台标题
    iserver频繁崩溃、内存溢出事故解决小记
    Java反射机制详解 及 Method.invoke解释
    window下maven的环境搭建
    window下mongodb的安装和环境搭建
    centos7 安装 redis4.0.8
    centos7 安装mysql5.7.20(yum方式)
  • 原文地址:https://www.cnblogs.com/sexintercourse/p/12262232.html
Copyright © 2011-2022 走看看