-
Notifications
You must be signed in to change notification settings - Fork 10.3k
'ViewContext' does not contain a definition for 'Controller' #1060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
cc @rynowak |
@dougbu @Eilon - should we expose |
@rynowak it does seem like a common need. I just wish there was a pattern for extension methods (e.g. on |
Regardless, I'd say if you need more services than |
Agree end users don't need But those writing What's most surprising to me is that |
@rynowak you can't @dougbu why would HTML helpers be any less likely to need URL helpers? That's probably the most common case. No one replaces IHtmlGenerator. |
Agreed. But those extending Separately I dislike exposing |
Not sure I understand. Are you saying someone writing an HTML helper needs |
Using tried-and-true "if we need it, so will they" logic, those extending |
@dougbu I don't immediately see the problem with, for example, exposing Controller, which has an IUrlHelper property, via the ViewContext, like it was before. |
@dougbu I doubt anyone would write helpers like ours, because ours are just core fundamental input elements. Most helpers I've seen are more domain-specific, and don't re-use our stuff, or people just write their own stuff from scratch. |
Is there any further development on the issue with accessing the controller? |
@Halofreak1990 we mostly discussed If yes, I recommend creating a brand new helper class over extending |
Yes. That's correct. |
This issue is being closed because it has not been updated in 3 months. We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate. |
Is there a workaround for the ViewContext.Controller in asp.net core? Could someone put a link here. I am migrating an application to core 2 and I have controllers with extension methods which i access from my views e.g if(ViewContext.Controller.HasRole("HRManager"){...}. I really need this to work and I can't seem to get any headway! |
Hi, it looks like you are posting on a closed issue/PR/commit! We're very likely to lose track of your bug/feedback/question unless you:
|
For purposes of learning the new MVC 6 framework, I am in the process of converting a basic MVC 5 project to MVC 6. However, this project uses a few custom HtmlHelper extension methods, some of which use the Controller property of the htmlHelper's ViewContext to retrieve an UrlHelper instance to build an URL based on the passed 'action' and 'controller' parameters. This, however, produces the titular error message.
Was the omission of the Controller property an oversight or intentional, and if intentional, what do you suggest as workaround?
The text was updated successfully, but these errors were encountered: