Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Source Error:
Line 31: <div class="mybutton left"></div>
Line 32: <div class="mybutton middle">
Line 33: @Html.FirstButton("Back", "Marketing", "Finance", new { ID = Model. Finance.ID }, new { @class = "mybutton " }) </div>
Line 34: <div class="mybutton right">
Line 35: </div>
Posted
Updated 20-May-12 23:51pm
v6
Comments
Manfred Rudolf Bihy 14-May-12 8:51am    
Added appropriate tags! Please don't just wrap your whole answer in a text tag. Always use the correct tag for the type of code you posted.

Thanks for your cooperation!
Karthik. A 14-May-12 9:31am    
Instead of new { ID = Model. Finance.ID } can you try passing in a dictionary<string,object> ? Like new Dictionary<string,object> { {"something", 5 }} ? I guess this should fix your problem.
Edit - added mvc 3 tag.

1) TagBuilder is for building html tags. "styledbuttonprimary" is not a tag in html. Your helper method name has nothing to do with it.
2) Your helper method has 2 parameters, but you try to call it with 5. You build the method, you dont inherit it! So build a proper formal parameter list in the prototype, or dont add what you have allready in the body of the method.
3) You know, that you have added the "text" parameter three times? What for?
4) You can compose from the ID and the css class one single inline class:
C#
@Html.StyledbuttonPrimary("Back", new { ID = Model.Finance.ID, @class = "styledbutton" })

and
C#
public static MvcHtmlString StyledbuttonPrimary(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());
      }

5) Are you sure with IDictionary<string,object>? <string,string> would be better, I dont know if automatic casting will work in properly...
 
Share this answer
 
v7
Yes, you see it right. If you want compex html code to be built by your helper, you need to do exactly what you have included at the end of your comment:
you can use tagbuilders that have as InnerHtml the result of another tagbuilder. This is the way.
Here is how you can use your parameters to build the A tag:

C#
var anchorBuilder = new TagBuilder("a");
anchorBuilder.MergeAttribute("href", url.Action(actionName, controllerName, routeValues));
anchorBuilder.MergeAttribute("title", linkText);
anchorBuilder.MergeAttributes(htmlAttributes);


I think you can figure out the rest of the helper.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900