Posts

Showing posts from June, 2020

Routing in Asp.Net MVC with example

                       Routing in Asp.Net MVC with example           Routing is defined in the RegisterRoutes method inside the RouteConfig class.         this RouteConfig class resides in App_Start Folder.                public static void RegisterRoutes(RouteCollection routes)         {             routes.IgnoreRoute("{resource}.axd/{*pathInfo}");             routes.MapRoute(                 name: "Default",                 url: "{controller}/{action}/{id}",                 defaults: new { controller = "Account", action = "Index", id = UrlParameter.Optional }             );                     }         Routing is a pattern matching system . when any user request from the browser at runtime          Routing engine use routing table for matching user request URL pattern against the URL          a pattern that is defined in the Route table.  You can register one or more URL         patterns in the route table but name is require diffe

ASP.NET MVC Architecture

Image
                             ASP.NET MVC Architecture  MVC is Model, View, and controller. it separates an application into three-part     1)Model 2) View 3) Controller.  Let understand each part in details below:-  1)  Model :-  Model represents data and business logic. it maintains the data of the application.                        we can create an object of the model and using that object we can store                        and retrieve data from the database        2)  View :- View is User interface means UI.                     View Display data using a model to users and enable them to modify data.    3)  Controller :- Controller is a request handler.  The controller handles user requests.                              a user interacts with the view. The controller renders View with                               model data as a response.                                                                    

ASP.NET MVC Folder Structure

Image
                            ASP.NET MVC Folder Structure                                Hello, you will learn the folder structure of MVC . when we create a new MVC application it creates a default structure below:-                  Let Understand Folder                              1) App_Data :- This folder contains files like .mdf file  , XML file , localdb etc.               2) App_Start:- This folder contains files like a bundle.config.cs, filter.config.cs ,                                          RouteConfig.cs . this three file in MVC 5  include by default.                                          this file executed when application_start called from global.asax                                                        3) Content:-      This folder contains  CSS file ,image ,icon . by default bootstrap.cs,                                          bootstrap.min.cs, site.css are added in MVC5.             4) Controllers:- This folder contains class files and this class file inherit

How To Create an MVC application in Visual Studio 2019

Image
                                     Below is a step to create an MVC project.    1) First, need visual studio so before creating MVC application first install Visual studio        https://visualstudio.microsoft.com/downloads/    you can install the latest version from the above URL.  2) Open Visual Studio 2019 and click on create a new project.       3)  After creating a new project. it showing multiple templates. you can choose any template       based on your requirement.                     1) Search ASP.NET in search box        2) Find ASP.NET Web application. if you want to develop an application in VB(visual basic)            then select VB  template if you want to develop an application in C#            then select the C# template.      3) Click on Next.           4) Above image for configuring your new project          1) Project Name :- you can give any name.         2) Location:- You can give any location to the store the project.         3) click on Create.                

Non-Action Attribute in MVC

Image
                                         When you create an action method with public access modifier in the controller                       so you can access the method through URL from the browser.                       If you don't want to call a method through URL from browser then use nonaction                      attribute  in method                      Example:                                             public class LearnController: Controller                       {                               // GET: Learn                              public ActionResult Index()                              {                                return View();                               }                                [NonAction]                                 public ActionResult NonActionMethod()                                   {                                    return View();                                   }                       }                                           Wh