我是ASP.NET MVC的新手,正在编写一个代码,它已经在我已经完成的上一页上工作但是当我在另一个页面上使用它时,它突然不再起作用了。它应该显示一组要在模态上选择和显示的记录。一旦我运行代码,它就会继续出现这个错误 - “System.Web.HttpCompileException - External Component抛出一个Excepetion”
这是我的控制器上的代码:
public ActionResult DROrders()
{
var model = new OSSelectionViewModel();
foreach (var dr in deliveryRepo.GetDROrders())
{
var editorViewModel = new SelectOSEditorViewModel()
{
ORDER_ID = dr.ORDER_ID,
ORDER_NUMBER = dr.ORDER_NUMBER,
ORDER_DATE = dr.ORDER_DATE,
ORDER_DUE_DATE = dr.ORDER_DUE_DATE,
CUSTOMER_ID = dr.CUSTOMER_ID,
CUSTOMER_NAME = dr.CUSTOMER_NAME,
LOCATION_TYPE_ID = dr.LOCATION_TYPE_ID,
LOCATION_TYPE_NAME = dr.LOCATION_TYPE_NAME,
ADDRESS = dr.ADDRESS,
EMP_ID = dr.EMP_ID,
EMP_FIRST_NAME = dr.EMP_FIRST_NAME,
EMP_LAST_NAME = dr.EMP_LAST_NAME,
NET_AMOUMT = dr.NET_AMOUNT,
Selected = false
};
model.drselect.Add(editorViewModel);
}
return View(model);
}
[HttpPost]
public ActionResult DROrders(OSSelectionViewModel model)
{
try
{
int[] selectedIds = model.getSelectedIds().ToArray();
int num = selectedIds.Length;
int tmp;
for (int i = 0; i < num; i++)
{
tmp = selectedIds[i];
listDrOrder.Add(tmp);
testVar = testVar + 1;
listDROrder.AddRange(dritemrepo.GetDROrderdetailItem(tmp));
}
drstoreId = listDrOrder.ToArray();
TempData["listDROrder"] = listDROrder;
TempData.Peek("listDROrder");
return RedirectToAction("AddDR");
}
catch
{
return View();
}
return View(model);
}
以下是我的查看模型:
OSSelectionViewModel:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ebms_2.Models
{
public class OSSelectionViewModel
{
public List<SelectOSEditorViewModel> drselect { get; set; }
public OSSelectionViewModel()
{
this.drselect = new List<SelectOSEditorViewModel>();
}
public int[] getSelectedIds()
{
// Return an Enumerable containing the Id's of the selected items:
return (from dr in this.drselect where dr.Selected select dr.ORDER_ID).ToArray();
}
}
}
这些是我的观点..
SelectOSEditorViewModel.cshtml:
@model ebms_2.Models.SelectOSEditorViewModel
@*@{
ViewBag.Title = "SelectOSEditorViewModel";
}*@
<tr>
@Html.HiddenFor(model => model.ORDER_ID)
<td style="text-align:center">
@Html.CheckBoxFor(model => model.Selected, new { @class = "chkitem" })
</td>
<td>
@Html.DisplayFor(model => model.ORDER_ID)
</td>
<td>
@Html.DisplayFor(model => model.ORDER_NUMBER)
</td>
<td>
@Html.DisplayFor(model => model.ORDER_DATE)
</td>
<td>
@Html.DisplayFor(model => model.ORDER_DUE_DATE)
</td>
<td>
@Html.DisplayFor(model => model.CUSTOMER_NAME)
</td>
<td>
@Html.DisplayFor(model => model.LOCATION_TYPE_NAME)
</td>
<td>
@Html.DisplayFor(model => model.ADDRESS)
</td>
<td>
@Html.DisplayFor(model => model.FULL_NAME)
</td>
<td>
@Html.DisplayFor(model => model.NET_AMOUNT)
</td>
</tr>
<script type="text/javascript">
$(document).ready(function () {
var items = new Array();
$('input:checkbox:checked').each(function () {
items.push($(this).val());
});
$('#submit').click(function () {
alert(items);
});
});// document ready
</script>
和
@model ebms_2.Models.OSSelectionViewModel
@{
ViewBag.Title = "DROrders";
if (ViewBag.Samp != null)
{
foreach (var item in ViewBag.Samp)
{
<p style="font-weight:bold; color:red; font-size:large;">
@item.PRODUCT_ID
@item.PRODUCT_CODE
@item.QUANTITY_ORDERED
@item.MEASUREMENT_ID
@item.MEASUREMENT_NAME
@item.tmpStatus
</p>
}
}
}
<div class="container">
<h2>Orders</h2>
@using (Html.BeginForm("DROrders", "Sales", FormMethod.Post))
{
// Wrap the table element in a div named "checkboxes":
<div id="checkboxes">
<table id="tbl_drOrders" class="table table-striped table-bordered table-hover dt-responsive nowrap" cellspacing="0">
<thead>
<tr>
<th>
Select
</th>
<th>Id</th>
<th>
O.S. No.
</th>
<th>
Order Date
</th>
<th>Due Date</th>
<th>Customer Id</th>
<th>Customer Name</th>
<th>Location Type Id</th>
<th>Location</th>
<th>Address</th>
<th>Emp Id</th>
<th>Sales Person</th>
<th>Amount Due</th>
</tr>
</thead>
@Html.EditorFor(model => model.drselect)
</table>
</div>
<hr />
<br />
<input type="submit" name="operation" id="submitbutton" value="Submit Selected" />
}
</div>
<span id="spanResults"></span>
错误指向这行代码:
@Html.EditorFor(model => model.drselect)
似乎有什么问题?希望有人可以帮助我。提前谢谢!