MVC:Fundamentals
ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that enables a clean separation of concerns and that gives you full control over markup for enjoyable, agile development. ASP.NET MVC includes many features that enable fast, TDD-friendly development for creating sophisticated applications that use the latest web standards.
TIP:why do we use nuget package as it automatically helps in updating the third party dlls update and manages them well.
MVC:Model contain the data to display.controllers recieve the request and figure out what to do.they often build the model and select the view.View is the html we see in the browser.
Whenever a client(end user) hits the url of the site the runtime envoirmnet figures out which controller will process the logic this happens through the routing logic.In global.asax.cs in the application_start() method their is a method that
RouteConfig.RegisterRoutes(RouteTable.Routes);
Route defines a pattern to match against the incoming url like the below snippet we have the default route configured which matches the pattern and calls the appropriate controller to provide action.
public class HomeController : Controller-->It is derived from the base class controller
{
public ActionResult Index()-->Action
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";-->Viewbag is the tunnel between the controller and view
return View();-->this means the default view of index needs to be returned.
}
Whenever a client(end user) hits the url of the site the runtime envoirmnet figures out which controller will process the logic this happens through the routing logic.In global.asax.cs in the application_start() method their is a method that
RouteConfig.RegisterRoutes(RouteTable.Routes);
Route defines a pattern to match against the incoming url like the below snippet we have the default route configured which matches the pattern and calls the appropriate controller to provide action.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Controller class syntax:
{
public ActionResult Index()-->Action
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";-->Viewbag is the tunnel between the controller and view
return View();-->this means the default view of index needs to be returned.
}
}
Tip:Razor views are the view that intermingle the html and c# code(@ViewBag.Message.
Tip:the views in the shared folder are accessible to all views.for eg layout view
in this layout view we have @rnderbody which renders the index view.
Tip:Razor views are the view that intermingle the html and c# code(@ViewBag.Message.
Tip:the views in the shared folder are accessible to all views.for eg layout view
in this layout view we have @rnderbody which renders the index view.
