Have userID in view, need userName posted
-
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?
-
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?
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.
-
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?
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