我选择员工姓名时遇到问题;选择的姓氏是视图上显示的名称,但我希望更改员工姓名。比如我输入Trev然后点击添加,添加另一个名称Trudan;它应该显示所有的名称而不仅仅是Trudan。我怀疑这是因为for循环。
<table id=" myTable" >
<tr>
<th>@Html.CheckBox("TheOneCheckBoxToRuleThemAll")</th>
<th class="col-lg-3">Requisition Number</th>
<th class="col-lg-3 ">Employee</th>
<th class="col-lg-3 ">Expense Account</th>
<th class="col-lg-3 ">Description</th>
<th class="col-lg-3 ">Item Number</th>
<th class="col-lg-3 ">Quantity</th>
<th class="col-lg-3 ">Requisition Date</th>
</tr>
@{
if (@Model.items.Count > 0)
{
foreach (var item in Model.items)
{
<tr>
<td>@Html.CheckBoxFor(m => m.postTrnx, new { @class = "checkGroup1" })</td>
<td class="label">@Html.DisplayFor(m => m.reqNumber) </td>
<td class="col-lg-3 tabledata">@Html.DisplayFor(model => model.employeeDetails.getName)</td>
<td class="col-lg-3 tabledata">@item.expense_account.getDescription</td>
<td class="col-lg-3 tabledata">@item.description</td>
<td class="col-lg-3 tabledata">@item.itemNumber</td>
<td class="col-sm-1 tabledata">@item.quantity</td>
<td class="label">@Html.DisplayFor(m => m.reqDate)</td>
</tr>
}
}
}
</table>
[ActionName("RequisitionItem")]
[HttpPost]
[AcceptVerbs(HttpVerbs.Post)]
[AcceptParameter(Name = "Add", Value = "Add")]
public ActionResult AddItems(Requisition requisition, string expense_desc)
{
IssueDAO issuedb = new IssueDAO();
ViewBag.StoresReps = issuedb.SelectEmployeesByDept("Stores");
ViewBag.ReceivedByReps = issuedb.SelectEmployeesByDept(requisition.department);
//getIssue.docNumber = issue.docNumber;
//getIssue.docType = "Issue";
getRequisition.department = requisition.department;
getRequisition.employeeDetails.employeeNum = requisition.employeeDetails.employeeNum;
//getRequisition.processedbyDetails.employeeNum = issue.processedbyDetails.employeeNum;
//getIssue.expense_acccount = issue.expense_acccount;
//getRequisition.expense_account = requisition.expense_account;
getRequisition.reqDate = DateTime.Now;
getRequisition.reqNumber = getRequisition.reqNumber;
//Check to see if item is already exist on the current Issue
for (int i = 0; i < getRequisition.items.Count; i++)
{
if (getRequisition.items[i].itemNumber == requisition.item.itemNumber)
{
ViewBag.errorMessage = "Item already exists";
return View(getRequisition);
}
}
//Check that the user only enters one item per request
//if (getRequisition.items.Count >= 1)
//{
// ViewBag.errorMessage = "Error, Only one item per request ";
// return View(getRequisition);
//}
//Item validation Section
if (items.Count == 0)
{
itemtbl.connectionString = ConfigurationManager.ConnectionStrings["TWCL_OPERATIONSConnectionString"].ConnectionString;
try
{
items = itemtbl.getItems();//Gets items from database
}
catch (Exception ex)
{
LogWrite logWriter = new LogWrite(ex.ToString());
ViewBag.errorMessage = "Unable to Connect to Database. Please see Log file for more Information";
return View(getRequisition);
}
}
foreach (var item in items)
{
//Checks to see if item is in the database by searching for the item
if (requisition.item.description == item.description)
{
//Checks to see if the item number specified matches that specified for the item
if (requisition.item.itemNumber == item.itemNumber)
{
requisition.item.lineNum = getRequisition.items.Count + 1;//Sets the line number to the index of the item plus one so has to have the Line number begin at 1
requisition.item.expense_account.account_desc = expense_desc;
string acc_desc = Regex.Replace(requisition.item.description, @"[^a-zA-Z0-9ęąół]", " ");
requisition.item.description = acc_desc;
getRequisition.addItems(requisition.item);
//getIssue.processedbyDetails.employeeNum = issue.processedbyDetails.employeeNum;
getRequisition.reqNumber = requisition.reqNumber;
//Reset the item varaible of the model to empty so as to accept new values
ModelState["item.itemNumber"].Value = new ValueProviderResult("", "", CultureInfo.CurrentCulture);
ModelState["item.description"].Value = new ValueProviderResult("", "", CultureInfo.CurrentCulture);
//ModelState["item.price"].Value = new ValueProviderResult("", "", CultureInfo.CurrentCulture);
ModelState["item.quantity"].Value = new ValueProviderResult("", "", CultureInfo.CurrentCulture);
return View(getRequisition);
}
ModelState["item.itemNumber"].Value = new ValueProviderResult("", "", CultureInfo.CurrentCulture);
ModelState["item.description"].Value = new ValueProviderResult("", "", CultureInfo.CurrentCulture);
//ModelState["item.price"].Value = new ValueProviderResult("", "", CultureInfo.CurrentCulture);
ModelState["item.quantity"].Value = new ValueProviderResult("", "", CultureInfo.CurrentCulture);
ViewBag.errorMessage = "The Item Number and Description do not match";
return View(getRequisition);
}
}
ModelState["item.itemNumber"].Value = new ValueProviderResult("", "", CultureInfo.CurrentCulture);
ModelState["item.description"].Value = new ValueProviderResult("", "", CultureInfo.CurrentCulture);
//ModelState["item.price"].Value = new ValueProviderResult("", "", CultureInfo.CurrentCulture);
ModelState["item.quantity"].Value = new ValueProviderResult("", "", CultureInfo.CurrentCulture);
ViewBag.errorMessage = "Invalid Item Description";
return View(getRequisition);
}