/// <param name="selectedValue"></param> /// <returns></returns> public static MvcHtmlString >{1}</option>", i.ID, i.Name); } sb.Append("</select>"); return MvcHtmlString.Create summary> /// <param name="html"></param> /// <returns></returns> public static MvcHtmlString
1: public static class LinkExtensions 2: { 3: //其他成员 4: public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName); 5: public static MvcHtmlString string hostName, string fragment, object routeValues, object htmlAttributes); 13: public static MvcHtmlString 1: public static class LinkExtensions 2: { 3: //其他成员 4: public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName); 6: public static MvcHtmlString
1: public static class RadioButtonListExtensions 2: { 3: public static MvcHtmlString RadioButtonList GenerateHtml(name, codes, repeatDirection, htmlAttributes, null); 7: } 8: public static MvcHtmlString fullHtmlFieldName, codes, repeatDirection, htmlAttributes, stateValue); 22: } 23: private static MvcHtmlString table.InnerHtml += tr.ToString(); 51: } 52: } 53: return new MvcHtmlString
要创建静态方法,你可以按照如下步骤来实现: 添加命了Helpers的文件夹 创建如下枚举类 public class ButtonHelper { public static MvcHtmlString = Enums.ButtonSize.Normal) { return new MvcHtmlString(string.Format("<button type "xs"; break; } return bootstrapSize; } } Button方法返回了一个MvcHtmlString public static MvcHtmlString BootstrapButton(this HtmlHelper helper, string caption, Enums.ButtonStyle = Enums.ButtonSize.Normal) { return new MvcHtmlString(string.Format("<button type
1: public static class ListControlExtensions 2: { 3: //其他成员 4: public static MvcHtmlString 而RadioButtonList和MvcHtmlString最终调用了辅助方法RadioButtonCheckBoxList显示了最终的HTML生成,该方法定义如下。 1: public static class ListControlExtensions 2: { 3: public static MvcHtmlString CheckBoxWithValue (element.ToString()); 32: } 33: 34: private static MvcHtmlString RadioButtonCheckBoxList (HtmlHelper htmlHelper, string listName, Func<ListItem, MvcHtmlString> elementHtmlAccessor) 35:
1: public static class ListControlExtensions 2: { 3: public static MvcHtmlString RadioButtonList ListControlUtil.GenerateHtml(name, codes, repeatDirection,"radio",null); 7: } 8: public static MvcHtmlString fullHtmlFieldName, codes, repeatDirection, "radio", metadata.Model); 15: } 16: 17: public static MvcHtmlString ListControlUtil中生成相关Html的逻辑定义如下: 1: public static class ListControlUtil 2: { 3: public static MvcHtmlString table.InnerHtml += tr.ToString(); 58: } 59: } 60: return new MvcHtmlString
public static class CustomHelpers { //Submit Button Helper public static MvcHtmlString SubmitButton string buttonText) { string str = "<input type=\"submit\" value=\"" + buttonText + "\"/>"; return new MvcHtmlString (str); } //Readonly Strongly-Typed TextBox Helper public static MvcHtmlString TextBoxFor<TModel, TValue this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel,TValue>>expression, bool isReadonly) { MvcHtmlString html = default(MvcHtmlString); if (isReadonly) { html = System.Web.Mvc.Html.InputExtensions.TextBoxFor
1: public static class ValidationExtensions 2: { 3: //其他成员 4: public static MvcHtmlString ValidationMessage(this HtmlHelper htmlHelper, string modelName); 5: public static MvcHtmlString 1: public static class ValidationExtensions 2: { 3: //其他成员 4: public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper); 5: public static MvcHtmlString ValidationSummary (this HtmlHelper htmlHelper, string message); 7: public static MvcHtmlString ValidationSummary
1: public static class SelectExtensions 2: { 3: public static MvcHtmlString DropDownList(this htmlHelper.DropDownList(name, listItems, bindingOption.OptionalLabel); 8: } 9: public static MvcHtmlString TProperty>(expression, listItems,bindingOption.OptionalLabel); 14: } 15: 16: public static MvcHtmlString htmlHelper.ListBox(name, listItems, bindingOption.OptionalLabel); 21: } 22: public static MvcHtmlString
Html.RenderPartial会将分部View的结果直接写入HTTP 响应流中,而 Html.Partial会返回 MvcHtmlString值。 什么是MvcHtmlString,为什么 Html.Partial返回的是MvcHtmlString 而不是字符串? 根据MSDN规定,”MvcHtmlString”代表了一个 HTML编码的字符串,不需要二次编码。 当不适用razor编码时,使用 MvcHtmlString,MvcHtmlString是razor的一种表示,即“字符串已经编码完毕,不需要其他编码”。 Html.RenderAction会将Action 方法的执行结果直接写入HTTP 响应请求流中,而 Html.Action会返回MVCHTMLString。
1: public static class ChildActionExtensions 2: { 3: //其他成员 4: public static MvcHtmlString Action(this HtmlHelper htmlHelper, string actionName); 5: public static MvcHtmlString Action( this HtmlHelper htmlHelper, string actionName, object routeValues); 6: public static MvcHtmlString HtmlHelper htmlHelper, string actionName, RouteValueDictionary routeValues); 8: public static MvcHtmlString htmlHelper, string actionName, string controllerName, object routeValues); 9: public static MvcHtmlString
id="+id+"&type="+type)) @Html.Encode()对输出内容编码,防止攻击 原样输出HTML str="
MvcNHibernateFirst.Web.Extensions { public static class SelectExtension { public static MvcHtmlString return DDLDeptOu(htmlHelper, name, null, htmlAttributes); } public static MvcHtmlString
1 public static MvcHtmlString DropDownListForEx<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper } 33 34 tag.InnerHtml = optionsHtml.ToString(); 35 return new MvcHtmlString
RenderSection(“PageSpecificStyleSheetIncludes”, required: false) @Html.Partial:在布局页中,把一个个View给镶入进来并回传的一个Object (MvcHtmlString
1: public static class BootstrapMenuExtensions 2: { 3: public static MvcHtmlString SiteMap.Providers.Cast<SiteMapProvider>().First(); 8: return new MvcHtmlString( RenderMenu
public static class InputExtensions { private static MvcHtmlString InputHelper(HtmlHelper htmlHelper bool isExplicitValue, string format, IDictionary<string, object> htmlAttributes); } private static MvcHtmlString
public static class HtmlHelperExtensions { public static MvcHtmlString CustomButton(this HtmlHelper htmlHelper, string text) { return new MvcHtmlString($"<button>{text}</button>"); } }
Suggestion.PlaseChooseToOperatingRecords' 7.工具栏的增、删、改按钮一样每次粘贴的代码也不少,我们应该扩展Mvc的HtmlHelper的封装,之后我们@html.就出来了多方便,以后还用于权限控制 这个必须返回MvcHtmlString /// <param name="hr">分割线</param> /// <returns>html</returns> public static MvcHtmlString sb.Append("
"); } return new MvcHtmlString文件名为:ASP_Page_views_XXX_ActionXXX_cshtml 程序集名由代码可知: 1 public static MvcHtmlString ListViewAssemblies AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.StartsWith("App_Web_"))) 5 { 6 //omit 7 } 8 return new MvcHtmlString