【发布时间】:2015-10-27 07:44:43
【问题描述】:
在 ASP.NET 4 中使用的 System.Web.Mvc.Html.InputExtensions 的 ASP.NET 5 等效项是什么?
请看下面的例子:
public static class CustomHelpers
{
// Submit Button Helper
public static MvcHtmlString SubmitButton(this HtmlHelper helper, 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(htmlHelper,
expression, new { @class = "readOnly",
@readonly = "read-only" });
}
else
{
html = System.Web.Mvc.Html.InputExtensions.TextBoxFor(htmlHelper, expression);
}
return html;
}
}
【问题讨论】:
标签: c# html-helper asp.net-core asp.net-core-mvc