What is the NonActionAttribute in mvc?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sachin SinghRank #66 · 26.2K reputationPosted Sep 24, 2022, 4:36 AM EDT
Point 1. All public methods inside an MVC controller are Action methods. Meaning, they can directly be accessed through url ex:-(/Home/index) where Index is an action method.
point 2. There are situations where we create methods just for business requirement and should not be accessible from url .
in the below example we are displaying employees from Index() action method, which gets the list from employees() method, employees() method should not be an action method as we don't want user to access this method. so we can mark it as non Action attribute.
public ActionResult Index() { var list=employees(); return view(list); } [NonAction] public List employees() { return new List{new Employee(){id=1,Name='sachin'},new Employee(){id=2,Name='Test'}}; }Rajanikant HawaldarRank #110 · 20.2K reputationPosted Sep 24, 2022, 5:01 AM EDT
https://www.c-sharpcorner.com/interview-question/what-is-the-use-of-nonactionattribute-in-asp-net-mvc