Posts

Showing posts from June, 2015

ASP.Net MVC Tute 4 - Create a List from IList

Image
ASP.Net MVC Tute 4 - Create a List from IList In this post I'll explain how to show data in a list. I have define this inside the Controller's Item ActionResult. You can arrange these in proper locations. 1. Create IList using a Model.         private static IList<Item> items = new List<Item>()         {             new Item()             {                 Id = 1,                 ItemName = "iPhone",                 Price = 99000             },             new Item()             {                 Id = 2,                 ItemName = "Lumia 520",         ...

ASP.Net MVC Tute 3 - Data Passing and Navigation

Image
ASP.Net MVC Tute 3 (Starter) - Data Passing and Navigation Let's see what are the other methods that provided to pass data to Views and Navigate using links. View Data and View Bag ViewData is a dictionary like data type. Inside controller: ViewData["ItemData"] = "Item data"; Inside View: View Data: @ViewData["ItemData"] ViewBag is dynamic data type Inside controller: ViewBag.ItemBag = "Item data in a bag"; Inside View: View Bag: @ViewBag.ItemBag TempData is use to store data that is survive for redirect. Inside controller: TempData["Survive"] = "Item data survived"; Inside View: Temp Data: @TempData["Survive"] URL Navigation 1. Lets create another ActionResult in ItemsController.         public ActionResult Item()         {             return View();         } 2. Create a view called Item by right click on the View and Add View. <!DOCTYPE html> ...

ASP.Net MVC Tute 2 - Create a Project

Image
ASP.Net MVC Tute 2 - Create a Project In this post I'll explain how to start ASP.Net MVC project. Step 1: Create a MVC Project 1. Open Visual Studio 2. Select New Project 3. Under Web category 4. Select ASP.NET MVC Empty Web Application 5. Give a suitable name (I choose ERP, because we are going to do some ERP related functionality and our final product will be a tiny ERP solution.) and suitable path to store the project. 6. Click 'Ok'. Your project will be created. Now lets start the fun part. Lets get a small scenario. Scenario 1: Show some item details on item page. Lets consider and apply this to the MVC concept. To do that divide the sentences to MVC ;) Show some items details - This means view. View should have some item details. Then there should be a Item - Model Show item details on item page - This is the Control with the Model and the View. Ok then. Lets apply what we have found. 1. Create a Item model inside the Models folder. (I...

ASP.Net MVC Tute 1 - The Theory

Image
ASP.Net MVC Tute 1 (Starter) The Theory The theory is inside the name it self. M - Model V - View C - Controller When ASP.Net MVC project is created you can see there are 3 folders for Models, Controllers and Views within the project structure (See the figure bellow). Models folder  We create normal classes. Ex. Item class. public class Item { public int Id { get; set; } public string ItemName { get; set; } public double Price { get; set; } } Controllers Folder Use to handle the business logic. Ex. Create new Item public ActionResult Index() { Item item = new Item(); item.Id = 1; item.ItemName = "Lumia 820"; item.Price = 35000; return View(item); } Views Folder Use to manage the front end. Ex. Display Item details. @model ERP.Models.ItemModels.Item Index This is the Item page. ...