I am trying to send an Employee ID (1) from the EmployeeSelect.cfhtml view to the Workers_Compensation controller method "Create". I used the answers from this question: Using Html.ActionLink to call action on different controller
However, none of these answers work quite properly. When the Select button on the EmployeeSelect screen is pressed I need to navigate from https://localhost:44353/Employees/EmployeeSelect to https://localhost:44353/Workers_Compensation/Create/{ID} . But using the code from that question (and everywhere else I can find) what ends up happening is I navigate to https://localhost:44353/Employees/Create?Length=20 .
What am I doing wrong?
EmployeeSelect.cshtml
@model IEnumerable<HR_App_V1.Models.Employee>
@{
ViewBag.Title = "Employee Select";
}
<h2>EmployeeSelect</h2>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.First_Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Last_Name)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.First_Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Last_Name)
</td>
<td>
@Html.ActionLink("Select", "Create", new { id = item.ID })
</td>
</tr>
}
</table>
Workers_Compensation
public ActionResult Create(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Employee employee = db.Employees.Find(id);
if (employee == null)
{
return HttpNotFound();
}
System.Diagnostics.Debug.WriteLine("Employee name: " + employee.First_Name);
ViewBag.Claim_Ruling_TypeID = new SelectList(db.Claim_Ruling_Type, "ID", "Claim_Ruling_Type1");
ViewBag.EmployeeID = new SelectList(db.Employees, "ID", "ID");
ViewBag.fName = new SelectList(db.Employees, "First_Name", "First_Name");
ViewBag.lName = new SelectList(db.Employees, "Last_Name", "Last_Name");
ViewBag.WC_TypeID = new SelectList(db.WC_Type, "ID", "WC_Type1");
return View();
}
If I manually navigate to https://localhost:44353/Workers_Compensation/Create/{ID} then everything works perfectly. But if I try to use the Select button it does not.