2011-10-12 59 views
0

我能为这样ASP.Net MVC 3..0 Razor属性值?

public string MyProperty { get { return _GetValue(); } set { _GetValue(); } } 


public static string _GetValue() 
    { 
     string name = null; 
     using (HROEF.Entities context = new HROEF.Entities()) 
     { 
      var result = (from my linq Statement).First().ToString(); 
      name = result; 
     } 
     return name; 
    } 

属性设置值在我看来

@Html.DisplayFor(model=>Model.MyProperty) 

有什么事错在这?

它不显示在我看来的价值

任何帮助吗?

回答

1

一般来说,你不应该做数据库访问属性。这只是不好的做法。属性不应该执行可能超时的冗长操作,或者有其他问题。

至于为什么它没有显示你的价值,这很难说。很可能,你的linq查询根本没有返回任何结果。

+0

这是有道理的。因为当我在属性中写入linq查询时它第一次工作,但后来它停止显示。任何通知不使用这种方法的方法。 – HaBo