开发者

How do you store the results of a Query in an Application variable in WebMatrix?

开发者 https://www.devze.com 2023-02-05 05:20 出处:网络
I have a .cs file in my App_Code folder that is doing this: dynamic HomePageFeaturedItems=db.Query(\"dbo.homepage_featured_items\");

I have a .cs file in my App_Code folder that is doing this:

dynamic HomePageFeaturedItems=db.Query("dbo.homepage_featured_items");
HttpContext.Current.Application["FeaturedItems"]=HomePageFeaturedItems;

I'd like to iterate over the results in my .cshtml like this:

@foreach(dynamic item in HttpContext.Current.Application["FeaturedItems"]){
        <li>
            <a href="/auctions/@(item.itemTitle)">@item.itemTitle</a>
        </li>
    }

But it obviously doesn't have an enumerator. I've开发者_StackOverflow中文版 been trying to wrap my head around how WebMatrix returns results...

Should I be storing it in the application variable in a different way?


I ended up writing objects and making Lists of them, and then placing that in the Application variable...not really the dynamic magic I think they intended but it works.

0

精彩评论

暂无评论...
验证码 换一张
取 消