Click below for Step by Step and Interview Q & A (dotnetinter) wrote,
Click below for Step by Step and Interview Q & A
dotnetinter

ASP.NET MVC interview question on ActionName and NoAction

What isActionName and NoAction attribute?

ActionName
Normally we call public methods in controller as Action methods. Now many time it happens that we want to create actin methods which we will be available to external users with some different name. We can do that with the help of action name attributes.

Code
[ActionName("MyAction")]
publicActionResultActionMethod()
{
return View();
}
Advantages


  • Two action methods can be defined with same name now but exposed with 2 different name.

[ActionName("MyAction")]
publicActionResultActionMethod()
{
return View();
}
[ActionName("MyAction")]
publicActionResultActionMethod(int i)
{
return View();
}

  • ActionName may contain any special character it.

  • ActionName may start with number.

NoAction
It’s another useful attribute which can be used with ActionMethods.
We use this when we want to create public methods inside Controller but want to restrict user from access it via directly.
[NoAction()]
publicActionResultActionMethod()
{
return View();
}
server
Tags: actionname, asp.net mvc interview questions, csharp interview questions, information technology questions, model view controller interview question, noaction, programming interview questions
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments