How to Get current controller or action name in ASP.NET MVC
By Tan Lee Published on Feb 18, 2024 1.29K
This tutorial shows you how to get current controller or action name in ASP.NET MVC using c# code.
As you know, The RouteData object contains information about the current routing path.
To get a current controller name you can write
@ViewContext.RouteData.Values["controller"].ToString()
and get a current action name
@ViewContext.RouteData.Values["action"].ToString()
- Implement security headers for an ASP.NET Core
- How to add security headers to an ASP.NET Core Application
- How to Initialize TagHelpers in ASP.NET Core with Shared Data
- Essential Tips for Securing Your ASP.NET Website
- Top Security Best Practices for ASP.NET
- Boost Your ASP.NET Core Website Performance with .NET Profiler
- The name 'Session' does not exist in the current context
- Implementing Two-Factor Authentication with Google Authenticator in ASP.NET Core
Categories
Popular Posts
Structured Data using FoxLearn.JsonLd
Jun 20, 2025
Implement security headers for an ASP.NET Core
Jun 24, 2025
What Are RESTful Web Services?
Feb 19, 2024
Plus Admin Dashboard Template
Nov 18, 2024