MVC 生成Html字符串MvcHtmlString CacheHelper用法

Html页面
1  <div class="nav">

2         @Html.BuildNav(userInfo.UserID)

3         <div class="clear">
CS
using System;

using System.Collections.Generic;

using System.Globalization;

using System.Linq;

using System.Security.Principal;

using System.Text;

using System.Web.Mvc;



namespace MFK.HTML

{

    public static class HTMLBuildControl

    {

        /// <summary>

        /// 生成一级导航链接

        /// </summary>

        /// <param name="helper"></param>

        /// <param name="userID">用户编号</param>

        /// <returns></returns>

        public static MvcHtmlString BuildNav(this HtmlHelper helper,int userID)

        {

            string key = string.Intern("UserNav_" + Current.UserName);

            if (CacheHelper.IsExist(key))

            {

                return MvcHtmlString.Create(CacheHelper.Get(key).ToString());

            }

            else

            {

                List<ddd> list = BLLModel.GetControllist(userID);

                StringBuilder html = new StringBuilder();

                html.Append("<ul>");

                  for (int i = 0; i < list.Count; i++)

                {

                    html.Append(<li>list.name</li>));

                }

                html.Append("</ul>");

                CacheHelper.Add(key, html.ToString());

                return MvcHtmlString.Create(html.ToString());

            }

            

        }

}

}

你可能感兴趣的:(String)