Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewData.Model and ViewData.Eval

In my Controller I have been setting

ViewData.Model = DBModel.Table.Take(1).Single();

Where DBModel is create by DBML file of Linq-to-SQL

And I can access the Value thro' ViewData.Eval("ColumnName"),

But If I create my own class

Class Test{

public string Col = "Testing ViewData";

}

Test objTest = new Test();

ViewData.Model = objTest;

Now If I try to get ViewData.Eval("Col") returns null.

Both I tried to store in ViewData.Model.

Whats the problem on this.

like image 444
Santhosh Avatar asked Aug 18 '26 04:08

Santhosh


2 Answers

Your definition of Col is a field, not a property. ViewData.Eval() only works against properties.

like image 137
Levi Avatar answered Aug 20 '26 23:08

Levi


The NerdDinner tutorial should give you a good feel for how this is all supposed to work. Eval is not generally used in ASP.NET MVC.

The ViewData section should be of particular interest to you.

like image 22
Robert Harvey Avatar answered Aug 20 '26 23:08

Robert Harvey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!