You've created a list of strings. You've then created three data objects, thrown them away, and then added the names of the local variables as strings to your list.
As a result, the
ViewBag.UData
property contains a list of
string
objects, and the
item
variable in your
foreach
loop is a
string
. Since the
string
type doesn't contain properties called
Name
or
Grade
, you get a compiler error.
Change your code to pass a list of
data
objects instead:
public ViewResult register()
{
List<data> s1 = new List<data>();
data d1 = new data() { Number = 1, Name = "varma", Grade = "A" };
data d2 = new data() { Number = 2, Name = "kumar", Grade = "c" };
data d3 = new data() { Number = 3, Name = "vasu", Grade = "B" };
s1.Add(d1);
s1.Add(d2);
s1.Add(d3);
ViewBag.Udata = s1;
return View();
}