ASP.Net MVC 3..0 Razor Property value?

本文关键字:Property value Razor Net MVC ASP | 更新日期: 2023-09-27 18:11:12

我可以为这样的属性设置值吗

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;
    }

In my View

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

这有什么不对吗?

它没有在我的视图中显示值

帮忙吗?

ASP.Net MVC 3..0 Razor Property value?

一般情况下,不应该使用数据库访问属性。这只是糟糕的练习。属性不应执行可能超时或有其他问题的冗长操作。

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