
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How can we provide an alias name for an action method in Asp .Net MVC C#?
ActionName attribute is an action selector which is used for a different name of the action method. We use ActionName attribute when we want that action method to be called with a different name instead of the actual name of the method.
[ActionName("AliasName")]
Controller
Example
using System.Collections.Generic; using System.Web.Mvc; namespace DemoMvcApplication.Controllers{ public class HomeController : Controller{ [ActionName("ListCountries")] public ViewResult Index(){ ViewData["Countries"] = new List<string>{ "India", "Malaysia", "Dubai", "USA", "UK" }; return View(); } } }
View
@{ ViewBag.Title = "Countries List"; } <h2>Countries List</h2> <ul> @foreach(string country in (List<string>)ViewData["Countries"]) { <li>@country</li> }
In the above since we have provided a different action name for the Index method, when we try to navigate with action name Index will get 404 error.
Now let us try to navigate using ListCountries action name.
- Related Articles
- How to use ViewBag in ASP .Net MVC C#?
- What is ViewData in ASP .Net MVC C#?
- How can we assign alias names for the action method in C# ASP.NET WebAPI?
- What is the significance of NonActionAttribute in ASP .Net MVC C#?
- What are the levels at which filters can be applied in ASP .Net MVC C#?
- What is the use of ChildActionOnly attribute in ASP .Net MVC C#?
- Can we use MySQL keyword as alias name for a column?
- What are the three segments of the default route, that is present in ASP .Net MVC\nC#?
- How to use an alias() for the parameter in PowerShell?
- How to create an ALIAS TAB2 for DB2 table TAB1?
- Can we create an object for an interface in java?
- How to implement an action listener using method reference in Java?
- How to use an Alias in MySQL calculations?
- Can we define an enum inside a method in Java?
- What is an alias in PowerShell?

Advertisements