1

I created a custom control in my ASP MVC application. Here is the Html Helper for the button

 public static MvcHtmlString EditButton(this HtmlHelper html, string action,
        string controller, bool state)
    {
        var url = new UrlHelper(html.ViewContext.RequestContext);

        //génrer le tag <a>
        var builder = new TagBuilder("a");

        //ajouter les différents attributs du tag
        builder.MergeAttribute("href", url.Action(action, controller));
        builder.MergeAttribute("alt", "edit");
        builder.MergeAttribute("title", "Edit");

        if (state)
        {
            builder.AddCssClass("edit_active");
        }

        else
        {
            builder.AddCssClass("edit_inactive");
        }

        string anchorHtml = builder.ToString(TagRenderMode.Normal);

        return MvcHtmlString.Create(anchorHtml);
    }

I want to add a parameter for the color of the button. How can I do that ?

Thanks.

1
  • 1
    what do you mean color? it looks like you are using css to determine the class for the button, can it not be done in the same manner if it is not based on state of the button? Commented Mar 6, 2012 at 11:29

1 Answer 1

1
builder.MergeAttribute("style", "color:red");
Sign up to request clarification or add additional context in comments.

1 Comment

This is how I would do it too, although maybe allow the color to be a variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.