ASP.Net MVC Tute 3 - Data Passing and Navigation

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>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Item</title>
</head>
<body>
    <div>
        <h3>This is the Item View.</h3>
    </div>
</body>
</html>

3. Go to the Index View and do this coding.

@Html.ActionLink("Go to the Item view", "Item")

Parameter 1 - Text that you want to display as the link.
Parameter 2 - View that you want to navigate.

Build the project and run it.


By click on this you navigate to the Item view.













Comments

Popular posts from this blog

Decompiling and debugging .Net dll files

Apache ActiveMQ 5 with .Net Core 3.1 and C#

Firebase with.Net Core and C#