views:

144

answers:

3

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.

A: 

use ((Test)Model).Col if your page does not implement ViewPage<Test>. Else use Model.Col

Gregoire
I have implement same for both the things
santose
IMO you really should use strong view model
Gregoire
+2  A: 

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.

Robert Harvey
A: 

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

Levi