开发者

ASP.NET MVC - Linq Query with Count returns anonymous type. How to display in view?

So I'm writing a query as follows:

Dim assSummary = From a In db.Assignments
                         Join ur In db.UserRegions
                         On a.Origin.ID Equals ur.Region.ID
                         Where ur.User.ID = usrid
                         Group By a.Status.Description _
                         Into AssCount = Count() _
                         Select AssCount, Description

In the controller I can return the data easily as follows:

For Each c In assSummary
    MsgBox(c.Description & " " & c.AssCount)
Next

If I pass the object through to the view using Viewdata("assSummary") = assSummary, how do I display the data? Every method I've tried results in messages about 'VB$AnonymousType_7(Of Integer,String) a开发者_开发技巧nd I don't know how to retrieve the data from the anonymous type.


In the directives of your page view, you can turn option strict off and use the late-bound dynamic functionality against the anonymous types as follows:

<%@ Page Language="VB" ContentType="application/rss+xml" 
     CompilerOptions="/optionstrict-" Inherits="System.Web.Mvc.ViewPage" %>

See http://www.thinqlinq.com/Default/Binding-Anonymous-Types-in-MVC-Views.aspx for a fuller sample/explanation.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜