1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help resolving an error when passing a query to a View...

Discussion in 'C#' started by DmitryS, Feb 24, 2011.

  1. #1
    I need help resolving an error... and may need an advice for a better implementation. I'm still trying to grasp the LINQ concept so I am stumbling along the way. Basically I just tried querying the aspnet_Users and aspnet_Membership tables and displaying the values to a view (not strongly typed)

    This is a working test code

    From HomeController ------------
    SEMrush
    var test = new TestEntities();
    ViewBag.UserIds = (
    from m in test.AspnetUsers
    orderby m.UserId ascending
    select m
    );

    return View();

    From Home View -----------------

    <ul>
    @{
    foreach (var x in ViewBag.UserIds)
    {
    <li>ID: @x.UserId</li>
    }
    }
    </ul>


    But this one gives me an error: {"'System.Guid' does not contain a definition for 'UserId'"}. I'm still using the above View for this.

    var test = new TestEntities();
    ViewBag.UserIds = (
    from m in test.AspnetUsers
    orderby m.UserId ascending
    select m.UserId
    );


    And this code too (since it's related above).

    var test = new TestEntities();
    ViewBag.UserIds = (
    from m in test.AspnetUsers
    join n in test.AspnetMemberships on
    m.UserId equals n.UserId
    orderby m.UserId ascending
    select new
    {
    m.UserId,
    n.Email,
    n.CreateDate
    }
    );


    How can I resolve this error? Is there a better way of passing the result of a database query to a view which is not strongly-typed?
     
    DmitryS, Feb 24, 2011 IP
    SEMrush