提交Html Helper不要使用htmlattribute [英] Submit Html Helper don't take htmlattribute
问题描述
嗨!我有提交按钮,而不是我的htmlAttribute。我按下按钮使按钮可选禁用,但是有效,但忽略了html属性。任何人都可以告诉我的代码有什么问题:
Hi! I have I Submit button that not take my htmlAttribute. I made the button to make the button optional disabled and that works, but the html attribute is ignored. Can anyone tell what is wrong with my code:
public 静态
string SubmitType < T >( 此
HtmlHelper < T > 助手 ,
字符串 名称 ,
字符串 值 ,
bool 已禁用 ,
对象 htmlAttributes )
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var builder
= new
TagBuilder ( " input" );
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;构建器 。 属性 。 添加 ( " type" ,
" submit" ) ;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;构建器 。 属性 。 添加 ( " name" ,
name );
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;构建器 。 属性 。 添加 ( " value" ,
值 );
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;构建器 。 属性 。 添加 ( " id" ,
name );
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;构建器 。 MergeAttributes ( new
RouteValueDictionary ( htmlAttributes ));
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; 如果
( 已停用 )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;构建器 。 属性 。 添加 ( "禁用" ,
"已禁用" ) ;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; 返回 构建器 。 ToString ();
&NBSP; &NBSP; &NBSP; }
public static
string SubmitType<T>(this
HtmlHelper<T> helper,
string name,
string value,
bool disabled,
object htmlAttributes)
{
var builder
= new
TagBuilder("input");
builder.Attributes.Add("type",
"submit");
builder.Attributes.Add("name",
name);
builder.Attributes.Add("value",
value);
builder.Attributes.Add("id",
name);
builder.MergeAttributes(new
RouteValueDictionary(htmlAttributes));
if
(disabled)
builder.Attributes.Add("disabled",
"disabled");
return builder.ToString();
}
感谢您的帮助!
推荐答案
此论坛致力于WebSitePanel主机面板开发。请在其他论坛上询问非WSP相关问题。
This forum is dedicated to WebSitePanel hosting panel development. Please ask non-WSP relative question on other forums.
这篇关于提交Html Helper不要使用htmlattribute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!