Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Have userID in view, need userName posted

Have userID in view, need userName posted

Scheduled Pinned Locked Moved ASP.NET
questiondatabase
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xnaLearner
    wrote on last edited by
    #1

    in my Get/Index view I am posting to my Post/Index method in the holidayController. So i am posting over the UserID, how can I use this to access the userName? Iv tried

    public ViewResult Index(int userID, string userName)
    {
    Person person = new Person();
    //this assigns person.Id to the user Id
    person.Id = userID;
    //i want to assign name of person to the string userName
    userName = person.name;
    }

    This is flashing up cant be null for person.name?

    M C 2 Replies Last reply
    0
    • X xnaLearner

      in my Get/Index view I am posting to my Post/Index method in the holidayController. So i am posting over the UserID, how can I use this to access the userName? Iv tried

      public ViewResult Index(int userID, string userName)
      {
      Person person = new Person();
      //this assigns person.Id to the user Id
      person.Id = userID;
      //i want to assign name of person to the string userName
      userName = person.name;
      }

      This is flashing up cant be null for person.name?

      M Offline
      M Offline
      Matt U
      wrote on last edited by
      #2

      Where is the user ID coming from? Do you have a database and a model (LINQ To SQL or EF)? If so, I believe you would just use a query to retrieve the Person entity where the ID matches the userID parameter. Then you could assign person.Name to the userName variable.

      djj55: Nice but may have a permission problem Pete O'Hanlon: He has my permission to run it.

      1 Reply Last reply
      0
      • X xnaLearner

        in my Get/Index view I am posting to my Post/Index method in the holidayController. So i am posting over the UserID, how can I use this to access the userName? Iv tried

        public ViewResult Index(int userID, string userName)
        {
        Person person = new Person();
        //this assigns person.Id to the user Id
        person.Id = userID;
        //i want to assign name of person to the string userName
        userName = person.name;
        }

        This is flashing up cant be null for person.name?

        C Offline
        C Offline
        CommDev
        wrote on last edited by
        #3

        Hi, try this: public ViewResult Index(int userID, string userName) { Person person = new Person(userID); //this assigns person.Id to the user Id //person.Id = userID; //i want to assign name of person to the string userName userName = person.name; } and you should define the class Person with id: public Person(int id) { //get the person from DB or ... _name = "data from DB"; } Comm100 - Leading Live Chat Software Provider

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups