Posts

Showing posts with the label MVC

ASP.Net MVC: ViewData, ViewBag and TempData with examples

In this section, I will explain the purpose of ViewData, ViewBag, and TempData with examples. ViewData 1. ViewData is derived from the ViewDataDictionary class and is basically a Dictionary object i.e. Keys and Values where Keys are String while Values will be objects. 2. Data is stored as Object in ViewData. 3. While retrieving, the data it needs to be Type Cast to its original type as the data is stored as objects and it also requires NULL checks while retrieving. 4. ViewData is used for passing value from Controller to View. 5. ViewData is available only for Current Request. It will be destroyed on redirection. Syntax:- C# Code: public class Parent1Controller : Controller { public ActionResult Index() { ViewData[ "Message" ] = "Welcome to Dotnet Builders Tutorials" ; return View(); } } .CSHTML CODE: < html > < head >     < meta name ="viewport" co...

MVC CRUD Operation - With Example

Image
MVC CRUD Operation: CRUD operation is nothing but to perform (CREATE, RETRIEVE, UPDATE and DELETE) records (collections of data) using the database. Here I Explained how to perform CRUD operation in ASP.NET MVC using EF (Entity-Framework) with Examples. What is Entity-Framework? Entity Framework is an ORM framework. ORM stands for Object Relational Mapping. Object Relational Mapping framework automatically creates classes based on database tables, and the vice versa is also true, that is, it can also automatically generate the necessary SQL to create database tables based on classes. Overview: This article will explain MVC base operations rather than any fundamentals and anything like that so if you are new to MVC then I'll suggest you first explore the basics, it will hardly take a few hours then you can read this article. In spite of these entire one more thing, I'm using MVC4 here for these operations. You can use any version but in the earli...

Understanding the basic concepts in MVC C#

Image
What is MVC in C#? The  ASP.NET MVC  is a Web Application Framework  developed by Microsoft. It is an open source implemented using visual studio 2012 and above version. ASP.NET MVC allows software developers to build a web application  as a composition of three roles:  Model, View, and Controller . The MVC model defines web applications with 3 logic layers: ·          Model (business layer) ·          View (display layer) ·          Controller (input control) (1) The Model interacts with the data source (DB or whatever) and gives you access to your data. (2) The View interacts with the client, it receives input from somewhere and hands off the data to the Controller it also listens to the Controller to make sure it's displaying the correct data. (3) The Controller is where all the mag...