views:

75

answers:

2

I have this helper in my view:

<%= Html.StandardOverlayCreateButton<EmployeeController>()%>

It creates the following HTML:

<a rel="#overlay" href="/Employee/Create">
<button type="button">
Create</button>
</a>

I do not like this anyway.

Any suggestions :) ?

I also askmyself when to create html helper extension and when just write the pure HTML code?

+1  A: 

In this case I think the helper is warranted as the amount of HTML "code" you're replacing is significant and conceptually a single entity, i.e., a styled "button". You can get access to the controller, however, in the view by using the ViewContext property on the ViewPage.

tvanfosson
Thanks, now I a have button that knows its controller name and the button has 0 parameters and in my view I have not to import the namespace of the given controller :)
Rookian
+2  A: 

I don't see why specifiying the controller in the HTML helper function isn't great. It will help with refactoring as it's strongly typed and it'll help get intellisense.

As for the extension / write html argument ... if you are going to use the same functionality again and again, write the HTML helper extension method :-)

Hope this helps.

WestDiscGolf
for what I use ascx controlls? Do they still have a meaning in ASP.NET MVC?
Rookian
ascx user controls are used for partial views in asp.net mvc, although they can also be used for custom control formatting through the view helpers (eg for Calendar displays) afaik. Does that answer your question as I don't quite fully understand your comment? Cheers
WestDiscGolf
In ASP.NET Webforms I think I would have written an ascx control and I just ask myself when do I use which approach.
Rookian
It's hard to compare webforms and mvc as they are different. However, personally for little, but custom, html outputs like your overlay button I'd do a html helper extension. I'd use an ascx for a large bit of customisation, such as a complex calendar async picker as a field template.
WestDiscGolf