Some background. A user takes a personality assessment based on a job that he/she is applying for. The Managers of the company can then go into the system and pull up that report. Scoring of this is done on the stanine system (standard nine bell curve). Every job has their own benchmark pattern that is displayed in the report (a benchmark pattern is the range of stanines within a particular dimension that are ideal for the candidate to score within). The report is accessed by clicking a link displayed as a button on the page.
Our customer would like for us to provide an option for the viewing manager to view the report using other benchmark patterns. So I have created a form on the page where the manager can select different jobs via a drop down. My issue is that the dropdown is marking as selected the job the applicant took the assessment for and i do not want that to be the case.
I thought that I needed to provide the selected value in dropdowns
Here is the code
//Models used
public class Applicant
{
public string ApplicationId { get; set; }
public string UserId { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
public int JobId { get; set; }
public int LocationId { get; set; }
public DateTime DateTaken { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string JobTitle { get; set; }
public string City { get; set; }
public int Completed { get; set; }
public bool Finished { get; set; }
public bool Viewed { get; set; }
}
public class Jobs
{
public string JobTitle { get; set; }
public int JobId { get; set; }
public bool LimitedViewing { get; set; }
public int AssessmentID { get; set; }
public bool Active { get; set; }
public bool Archive { get; set; }
public bool HasLocations { get; set;}
public List<Jobs> JobsList(string UserID)
{
using (SqlConnection oConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
{
using (SqlCommand oCmd = new SqlCommand())
{
try
{
oCmd.CommandText = "ListJobs";
oCmd.CommandType = CommandType.StoredProcedure;
oCmd.Parameters.Add("@UserID", SqlDbType.NVarChar).Value = UserID;
oCmd.Connection = oConn;
oConn.Open();
using (SqlDataReader reader = oCmd.ExecuteReader())
{
List<Jobs> myList = new List<Jobs>();
while (reader.Read())
{
Jobs job = new Jobs
{
JobId = Convert.ToInt16(reader[0]),
JobTitle = reader[1].ToString()
};
myList.Add(job);
}
return myList;
}
}
finally
{
oConn.Close();
oCmd.Dispose();
}
}
}
}
}
//Controller code
public ActionResult Details(string ApplicationId)
{
try
{
if (ApplicationId == "" || ApplicationId == null)
{
return RedirectToAction("Index");
}
string UserID = System.Web.HttpContext.Current.Session["UserID"] as String;
ViewData["UserID"] = UserID;
if (ViewData["UserID"] != null)
{
Applicant app = new Applicant();
var ThisApplicant = app.GetApplicantData(ApplicationId);
AdminUser admin = new AdminUser();
ViewBag.AdminEmail = admin.GetAdminUserEmail(UserID);
ViewBag.UserID = UserID;
Jobs job = new Jobs();
ViewBag.Jobs = new SelectList(job.JobsList(UserID), "JobId", "JobTitle");
return View(ThisApplicant);
}
ViewData["ReturnUrl"] = "Applicants/Index";
return View("LoggedOut");
}
catch (Exception ex)
{
ErrorOccured(ex);
}
return RedirectToAction("Index", "Error", new { Area = "" });
}
//The form in the view with the dropdown to allow for selecting different jobs
@using (Html.BeginForm("ViewDifferentJob", "Applicants", FormMethod.Post, new { id = "myForm" }))
{
<input type="hidden" name="ApplicationId" value="@Model.ApplicationId" />
<div class="row">
<div class="col-xs-6 col-md-3 col-md-offset-2"><label>Job pattern to view</label>@Html.DropDownList("JobId", (IEnumerable<SelectListItem>)ViewBag.Jobs, "Make Selection", htmlAttributes: new { @class = "form-control" })</div>
<div class="col-xs-6 col-md-3"><label>Report Type</label><select name="SsOnly" class="form-control"><option value="false">Full Report</option><option value="true">Scoresheet Only</option></select></div>
<div class="col-xs-3 col-md-3"><label> </label><input type="submit" value="View Assessment" class="btn btn-block btn-default btn-assessment" /> </div>
</div>
}
How do I make it so the dropdown does NOT mark as selected the job that applicant took the assessment for?