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());

    }
    }
    }

  • 相关阅读:
    mysql-5.7.15-winx64免安装版配置
    db2 表授权语句
    java 调用 .net webservice 示例
    打印内存高解决方案
    eclipse快捷键调试总结【转】
    DevExpress GridControl 自定义 summary 算法
    GEMR: Get the parent window for view
    弹出窗口
    WPF UI虚拟化
    WPF应用程序最小化到系统托盘
  • 原文地址:https://www.cnblogs.com/gcb999/p/MVC.html
Copyright © 2011-2022 走看看