Asp.net mvc 4 格式化要在HtmlHelper扩展中使用的Html字符串-MVC
我写了一个扩展方法:Asp.net mvc 4 格式化要在HtmlHelper扩展中使用的Html字符串-MVC,asp.net-mvc-4,html-helper,string.format,Asp.net Mvc 4,Html Helper,String.format,我写了一个扩展方法: public static string XDropDown(this HtmlHelper helper,string name, string optionLabel,object selectedValue) { StringBuilder b = new StringBuilder(); b.AppendFormat("<select name='{0}' id='{0}'>", name);
public static string XDropDown(this HtmlHelper helper,string name, string optionLabel,object selectedValue)
{
StringBuilder b = new StringBuilder();
b.AppendFormat("<select name='{0}' id='{0}'>", name);
b.Append("</select>");
return b.ToString();
}
我是从局部的角度来使用它的,
它没有按预期进行渲染,
我知道我也可以使用标记生成器,
但急于知道这是否能起作用。使用作为返回类型,如下所示:
public static MvcHtmlString XDropDown(
this HtmlHelper helper,
string name,
string optionLabel,
object selectedValue)
{
StringBuilder b = new StringBuilder();
b.AppendFormat("<select name='{0}' id='{0}'>", name);
b.Append("</select>");
return MvcHtmlString.Create(b.ToString());
}
public静态MvcHtmlString XDropDown(
这个HtmlHelper助手,
字符串名,
字符串选项标签,
对象选择值)
{
StringBuilder b=新的StringBuilder();
b、 附录格式(“”,名称);
b、 附加(“”);
返回MvcHtmlString.Create(b.ToString());
}
public static MvcHtmlString XDropDown(
this HtmlHelper helper,
string name,
string optionLabel,
object selectedValue)
{
StringBuilder b = new StringBuilder();
b.AppendFormat("<select name='{0}' id='{0}'>", name);
b.Append("</select>");
return MvcHtmlString.Create(b.ToString());
}