ViewData.Model and ViewData.Eval

In my controller I installed

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

Where DBModel is created by DBML Linq-to-SQL file

And I can access the value of 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 tried to save in ViewData.Model.

What is the problem.

+3
source share
3 answers

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

+2
source

The NerdDinner tutorial should give you a good idea of ​​how all this should work. Evalnot commonly used in ASP.NET MVC.

ViewData​​strong > .

+2

use ((Test)Model).Colif your page does not implement ViewPage<Test>. Otherwise useModel.Col

0
source

Source: https://habr.com/ru/post/1731920/


All Articles