Posts

Showing posts from May, 2020

Explain terms of MVC ?

  MVC is Model, View, Controller.       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.                     

What is ViewData , ViewBag and TempData in MVC

    ViewData:-    ViewData is a dictionary object that is derived from the ViewDataDictionary class.    ViewData is a property of the ControllerBase class.    Viewdata is used to transfer data from controller to view.     It’s required typecasting for getting data and check for null values to avoid an error.      the syntax for ViewData is:-     ViewData["Message"] = "your Message";   ViewBag:-  ViewBag is a dynamic property that is used to transfer data from controller to view.  ViewBag is a property of the ControllerBase class.  ViewBag doesn’t require typecasting for getting data and check for null values.       the syntax for ViewBag is:-     ViewBag.Message= "your Message";      ViewBag & ViewData Example: public ActionResult Index() {     ViewBag.Message = "Your Messsage";     return View(); }   public ActionResult Index() {     ViewData["Message"] = "Your Message";     return View(); }   In View:- @ViewBag.Message @