I am using ASP.NET MVC with a SQL database backend. I have a table that lists individuals which I use for two fields in another table. One field is for the Chief Investigator (ChiefInvestigatorID), the other for the Principal Investigator (PrincipalInvestID). The same person can be in both fields.
When I use the dropdown list, it does correctly store the ID in the respective fields but the Title, Forename and Surname for each respective ID is not correctly showing. This screenshot shows the Principal Invest ID name appearing for the Chief Invest ID, too.
Here is the dropdown code in the controller:
var resname = _context.LocalResname?
.Select(s => new
{
Text = s.PersonID + " " + s.Title + " " + s.Forename + " " + s.Surname,
Value = s.PersonID,
})
.ToList();
ViewBag.ResNameList = new SelectList(resname, "Value", "Text");
This is the Details.cshtml page:
Here is a snippet of the Details.cshtml sheet code. I currently have the same 'lookup' of Title, Forename and Surname as shown here for the Principal Invest. How can I change this to ensure that both names are correctly displayed? Thank you.
<div class="row">
<div class="col-sm-2">
<div class="form-group">
<br />
<b> @Html.DisplayNameFor(model => model.ChiefInvestigatorID) </b>
<div class = "col-sm-10">
@Html.DisplayFor(model => model.ChiefInvestigatorID)
</div>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<br />
<b> @Html.DisplayNameFor(model => model.LocalResname.Title) </b>
<div class="col-sm-10">
@Html.DisplayFor(model => model.LocalResname.Title)
</div>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<br />
<b> @Html.DisplayNameFor(model => model.LocalResname.Forename) </b>
<div class="col-sm-10">
@Html.DisplayFor(model => model.LocalResname.Forename)
</div>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<br />
<b> @Html.DisplayNameFor(model => model.LocalResname.Surname) </b>
<div class="col-sm-10">
@Html.DisplayFor(model => model.LocalResname.Surname)
</div>
</div>
</div>
