Reputation: 14123
I have a Html button as follows:
<%=Html.Button("javascript:onSave();", CommonResource.Save, "SaveButton")%>
Where:
parameter1 - action
parameter2 - name
parameter3 - id
How can I add parameter for CSS class? I tried doing this:
<%=Html.Button("javascript:onSave();", CommonResource.Save, "SaveButton",new { @class="save" })%>
but that does not work. I only get the looks but no action is performed.
Upvotes: 0
Views: 91
Reputation: 251062
You need to look at your implementation of Html.Button
as it isn't a standard HtmlHelper.
It probably doesn't have a parameter for htmlAttributes, in which case you could use this implementation, which does!
public static class HtmlButtonExtension
{
public static MvcHtmlString Button(this HtmlHelper helper, string text,
IDictionary<string, object> htmlAttributes)
{
var builder = new TagBuilder("button");
builder.InnerHtml = text;
builder.MergeAttributes(htmlAttributes);
return MvcHtmlString.Create(builder.ToString());
}
}
Upvotes: 0
Reputation: 1039080
This looks like ASP.NET MVC. If so please tag your question appropriately. There's no Button
helper in the standard MVC library so I guess that this is some custom or third party helper you are using. If there's no overload allowing you to pass htmlAttributes then this cannot be done.
Upvotes: 1