dotNet Core

Passing Data from Controller Action Method to View in ASP.NET Core

Posted on Updated on

We can pass the Data from Controller to View in 2 ways.

1. ViewData

Example for Single value data

Action Controller Code

ViewData[“MyViewName”] =” Type string to pass here”;

To show it in the View, we can write @ViewData[“Key”]

View Code


@ViewData[“MyViewName”]

Controller Action Code

List list=new List();
For(int i=0; i<10;i++)
{
list.Add(i);
}
ViewData[“ListItems”]=list;

Then, in View we need to set the value of ViewData[“ListItems”] as the collection of integer list.

View Code

@foreach (int I in (List)ViewData[“ListItems”])
{
@i <br/>
}

2. ViewBag

 ViewBag is easier and simple way. It accepts data as objects so we can set any type of data.

Controller Code

ViewBag.MyViewBagName=”Send the data that you wanted ”;

View Code

@ViewBag. MyViewBagName

Another example to set the list of integers in ViewBag

Control Code

List list=new List();
For(int i=0; i<10;i++)
{
List.Add(i);
}
ViewBag.ListItems=list;

View Code

Advertisements

What’s New in Visual Studio 2017

Posted on Updated on

Visual Studio is a productivity game changer for C#! The .NET Compiler Platform (“Roslyn”) enables many new experiences that will change the way you write and debug code. In this session, we’ll dig into features that bring a new level of awesome to the C# language and IDE experience. Come learn about new language features, refactoring support, major debugging enhancements, code-aware frameworks, and much more!

https://channel9.msdn.com/Events/dotnetConf/2017/T118/player

 

What’s New in Entity Framework Core 2.0

Posted on Updated on

Entity Framework Core is a lightweight, extensible, and cross-platform version of the popular Entity Framework data access technology. In this session we’ll look at what’s new in EF Core 2.0 and what the team has planned for upcoming releases.

Video:

https://channel9.msdn.com/Events/dotnetConf/2017/T221/player