Prevent Controller Method from being Invoked

Controller is a Class that inherits from the base class System.Web.Mvc.Controller. Any public method exposed by a controller is exposed as a controller action.If you want to prevent a public controller method from being invoked, you put the "NonAction" attribute over the method name.By default Index() action is the default action that is invoked on a controller on when no explicit action is mentioned.

For example

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

 

namespace ControllerApplication.Controllers

{

    public class TestingController : Controller

    {

        //

        // GET: /Testing/

        [NonAction]

        public ActionResult Index()

        {

            return View();

        }

    }

}

Ebook Download
View all
Learn
View all