0

I am new to ASP.Net and am building an MVC project in VS2013 I have the following actionResult

public ActionResult Index()
        {
            LaundryUsers db = new LaundryUsers();
            var users = db.Laundries.Where(u => u.UserId == WebSecurity.CurrentUserId);

            if (users == null)
            {
                return HttpNotFound();
            }

            return View(users);

        }

The result always throws a null exception but The data is in the table. When I do a break the userid is in the currentUserId. I am from a visual basic background on Desktop
apps. Thanks in advance

3
Contributors
2
Replies
15
Views
3 Years
Discussion Span
Last Post by cxzei
0

Hard to say. Code looks fine. I suggest you break on line 4 and check whether db.Laundries contains any value at all.

0

try something like...

int myCount = 0;
foreach (Laundries l in users)
{
    myCount+=1;
}
if (myCount==0)...

one man's opinion...a table name should be the singluar name of the object it represents, user instead of users. For variables use List instead of the plural form, userList instead of users.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.