有沒有人有沒有使用MVC的Razor的經驗。我使用的是模板引擎從http://www.fidelitydesign.net/?p=208建立起來,但我不能在剃刀代碼中使用任何LINQ查詢例如在沒有MVC的情況下使用Razor時無法訪問Linq
<div>
@Model.Person.First().Firstname
</div>
這引發錯誤:
System.Collections.Generic.List' does not contain a definition for 'First' and no extension method 'First' accepting a first argument of type 'System.Collections.Generic.List' could be found (are you missing a using directive or an assembly reference
在這個例子中Model
包含下面
public class Person
{
public string FirstName { get; set; }
}
我想你也嘗試'@using System.Linq'? – BrokenGlass 2012-03-13 13:09:45
是的,我已經調試並檢查添加了彙編 – scully 2012-03-13 13:13:21
語法錯誤,'Model'是列表,所以'First'需要在'Model'上調用。 – ntziolis 2012-03-13 13:13:40