locked
Identifying an object using guids RRS feed

  • Question

  • User-1854552489 posted

    Really new to development, I've built an application where I handle all the user registration, so the user doesn't actually get to register themselves..I do it for them and then give them the login details.

    I can get the listing of all users okay, but I can't use the details, edit or delete actions because I don't know how to identify the GUID in the controller.  

    Normally I would expect to identify by doing this:

    public ActionResult Details(int UserId=0)
    {

    return View(db.Consultants.Find(UserId));
    }

    but seeing as though the db works with Guids and the UserId is nvarchar, I'm at a loss.

    Can anyone please help me?

    Monday, October 20, 2014 11:11 PM

All replies

  • User-821857111 posted
    public ActionResult Details (Guid UserId)
    {
       return View(db.Consultants.FirstOrDefault(c => c.UserId == UserId));
    }
    



    Tuesday, October 21, 2014 2:19 AM
  • User-1854552489 posted

    Hi Mike,

    Thanks for the response.  I wish I had better news but it didn't work out for me.

    In the db UserId is nvarchar.

    In the edmx and the modelview UserId is string.

    The generated UserId looks something like this: 2f3f713b-0acb-4785-a951-a9c62c825853.

    That's a Guid right?

    Anyway, even like this it doesn't work:

    public ActionResult Details (String UserId)
    {
       return View(db.Consultants.FirstOrDefault(c => c.UserId == UserId));
    }

    It's just returning blank fields.

    Tuesday, October 21, 2014 4:16 AM
  • User-821857111 posted

    That's a Guid right?

    If the database type is nvarchar and the C# type is string, then it's not a guid. It's a string that looks like a guid. Bit daft, really, but it is what it is.

    It's just returning blank fields.
    What does that mean? It should either return a Consultant object or null.

    Tuesday, October 21, 2014 6:45 AM
  • User-1854552489 posted

    What does that mean? It should either return a Consultant object or null.

    Hi, that is weird about the string looking like a guid.

    Well, it doesn't return an error but instead returns blank cells in a table:

    Consultant Details

    UserId:

    Name:

    Address:

    Email:

    Thursday, October 23, 2014 6:06 PM
  • User-1151753377 posted

    Hi,

    There is an article about the GUID in MVC and hope it could helpful for you

    http://support.microsoft.com/kb/224544

    Best Regards,

    Summer

    Wednesday, October 29, 2014 5:18 AM