In the view, for example, in “_Layout.cshtml”
How to get the controller/action which called this view?
After found the controller/action name, then how to get the list of the attribute it has? Or test if it has an attribute?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
@ViewContext.Controllerwill give you the controller instance that returned this view. Once you get the instance, you get the type and once you have the type you get into Reflection to get the attributes this type is decorated with. Writing a custom HTML helper to perform this job could be worth it: