开发者

ASP.NET MVC: Is it possible to get the controllername inside of a view?

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 pur开发者_如何转开发e HTML code?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜