开发者

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

开发者 https://www.devze.com 2022-12-21 21:03 出处:网络
I have this helper in my view: <%= Html.StandardOverlayCreateButton<EmployeeController>()%>

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

精彩评论

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

关注公众号