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

    }
    }
    }

  • 相关阅读:
    Android Activity的事件分发机制-源码解析
    Android ViewGroup的事件分发机制-源码分析
    Android View的事件分发机制-源码解析
    Activity中的setContentView(R.layout.xxx)源码分析
    android 6.0动态权限的申请
    java 回行矩阵的打印
    Masonry解析ios屏幕适配
    CollectionsUtil 类
    Request.url请求路径的一些属性
    .net中HttpCookie使用
  • 原文地址:https://www.cnblogs.com/gcb999/p/MVC.html
Copyright © 2011-2022 走看看