I have a Ticket model with some basic ticket information.
What I want to do now is I want to be able to assign Agent to each Ticket.
For the Agent, I want to use the ASP.Net Identity Users which I already have.
I want to add property called AgentName and AgentID to this Ticket model.
In my Index View, I want to see a single Agent Name assigned to AgentName property and When I am editing a Ticket I want to have a drop down list of all available ASP.Net Identity Users (Agent Name) so that I can assign the ticket to.
I want to also have the ability to query all assigned Ticket to an specific Agent using AgentID so somehow I need to link each Ticket to an Agent using the AgentID.
How can I make this happen with code? Any help is appreciated.
So far I have this:
Public class Ticket
{
public int Id { get; set; }
Display(Name = "Ticket comes from")]
public string Source { get; set; }
}
In my ticket Edit(int id) HttpGet method I am fetching a Ticket information with the following code.
//HttpGet
public ActionResult Edit(int id)
{
Models.Ticket model = db.Ticket
.Include("Source")
.SingleOrDefault(m => m.Id == id);
if (model == null)
{
return new HttpNotFoundResult();
}
return View(model);
}
What I have tried
I have tried changing my Ticket model to something like this
Public class Ticket
{
public int Id { get; set; }
Display(Name = "Ticket comes from")]
public string Source { get; set; }
//....
// Now I want to have a property called AgentName and AgentID
//...something like this
public string AgentName {get; set;} //***I want this to display the User Name of the User in Index View page. But, I also want a dropdown list of user when I am in Edit mode so that I can change the AssignedToUser to have different user.
public string AgentID {get; set;}
}
To get all ASP.Net Identity User (Agents) I have something like this:
ViewBag.Agents = new SelectList(db.Users);
To display as drop down list in Edit mode I have something like this:
<div class="form-group">
@Html.LabelFor(model => model.AgentName, new { @class = "col-sm-4 control-label" })
<div class="col-sm-8">
@Html.DropDownList("Agents", ViewBag.Agents as SelectList, String.Empty, new { @class = "form-control" })
</div>
</div>
But nothing is working. When I am editing a Ticket, the Agent drop down list display some weir character like shown in the picture here. I want this to be a list of User Name.
DEBUG
@nurdyguy Put a debug stop on the line in the controller where you do ViewBag.Agents = new SelectList(db.Users)
;
This is what I got: