zoukankan      html  css  js  c++  java
  • mvc自定义扩展控件

    注意点 自定义类必须在System.Web.Mvc 类必须为静态扩展类.

    namespace System.Web.Mvc
    {
    public static class MyFormLable
    {
    public static MvcHtmlString GetForm<T>(this HtmlHelper Help, T Model)//要定义泛型,在方法中指定泛型
    {
    StringBuilder sb = new StringBuilder();
    sb.AppendLine(@" <fieldset>");
    sb.AppendLine(@" <legend>Fields</legend>");
    foreach (PropertyInfo model in Model.GetType().GetProperties())
    {

    sb.AppendLine(" <div class=\"editor-label\">");
    sb.AppendLine("<label for=\""+model.Name +"\">"+model .Name +"</label>");
    sb.AppendLine("</div>");
    sb.AppendLine("<div class=\"editor-field\">");

    sb.AppendLine(" <input id=\""+model .Name +"\" name=\""+model .Name +"\" type=\"text\" value=\"\" />");
    sb.AppendLine("<span class=\"field-validation-valid\" id=\"ID_validationMessage\"></span>");
    sb.AppendLine("</div>");

    }
    sb.AppendLine(@" </fieldset>");
    //sb.AppendLine(@" <% } %>");
    return MvcHtmlString.Create(sb.ToString());

    }
    public static MvcHtmlString PageSize(this HtmlHelper help, int? count,string actionName,string controller)
    {
    if (count == null) return null;
    StringBuilder sb = new StringBuilder();
    sb.AppendLine("<div>");
    for (int i = 0; i < count; i++)
    {
    sb.Append(" <a href=\"/" + controller + "/" + actionName + "?PageIndex=" + (i + 1) + "\">" + (i + 1) + "</a>");
    }
    sb.AppendLine("</div>");
    return MvcHtmlString.Create(sb.ToString());

    }
    }
    }

  • 相关阅读:
    python is == 区别
    python 元类 type metaclass
    树莓派 zero w 一根线使用
    python 类装饰器
    Oracle创建用户
    hibernate使用原生SQL查询
    工作流 jBMP4.4表结构
    (Mark)Myeclipse10.6 下怎么安装Jad插件
    (Mark=转)ehcache memcache redis
    Oracle 常用命令
  • 原文地址:https://www.cnblogs.com/gcb999/p/MVC.html
Copyright © 2011-2022 走看看