MVC – What is the Purpose of [ActionName()]
I was very curios about the purpose of ActionNameAttribute in these past 3 days and I worked around a lot to find something about it. I will try to tell a little about if you don’t know this attribute. When you give this attribute to an Action , the Action (Method) Name cannot be used at View part also you cant write it at the address bar from the browser as it written. Instead of this action (method) name you must use the string ; which you defined at [ActionName(“thestring“) ] so the real ActionName has been disabled. So what is the purpose of this attribute.
Sometimes you can’t see the needs of techniques and materials until you use them. Today I was working on a little project with MVC and I needed to give a name to an Action which includes a non-alphanumeric character . Then , it didn’t allow me to write that kind of a name as an ActionName . Guess what did solve my problem ? ActionNameAttribute 🙂
At the first picture as you see it gives a Syntax Error :
And the second picture as you see there is no error and now you can use the address as ” http://localhost/Home/Operation-Manage ”
I hope you were also curios about this attribute before reading this article , and I wish that curiosity has been satisfied by this article.
Take Care ! Bye 😉