The controller is the class in MVC which implements Controller base class which again implements ControllerBase.
public abstract class Controller : ControllerBase, IActionFilter, IAuthenticationFilter,
IAuthorizationFilter, IDisposable, IExceptionFilter, IResultFilter, IAsyncController, IController,
IAsyncManagerContainer
{
}
In the Controller class, it contains Controller Action methods. which are pointed to View to render the HTML in the browser when we requested using the URL.public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
When we create a Home Controller it should always end with end Controller. If we miss the
Controller Name with Home, MVC will not able to find the Home Controller and its Action methods
and View associated with Action Methods.
Add a view by right clicking on Index Action Method. Bydefault it will name the view as Index.
When we type the URL as home/index , it will automatically look for the view index.cshtm with
will render as plain HTML page in the browser.
No comments:
Post a Comment