<%using (Html.BeginForm("OrderDevice", "ImportXML", FormMethod.Post))
{ %>
<table id="OrderDevices" class="data-table">
<tr>
<th>
DeviceId
</th>
<th>
Id
</th>
<th>
OrderId
</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<input readonly="readonly" class="" id="DeviceId" type="text"
name="<%= Html.Encode(item.DeviceId) %>"
value="<%= Html.Encode(item.DeviceId) %>" style="width: 61px" />
</td>
<td>
<input readonly="readonly" class="" id="c" type="text"
name= "<%= Html.Encode(item.Id) %>" value="
<%= Html.Encode(item.Id) %>"
style="width: 50px" />
</td>
<td>
<input readonly="readonly" class="" id="OrderId" type="text"
name= " <%= Html.Encode(item.OrderId) %>"
value="<%= Html.Encode(item.OrderId) %> " style="width: 49px" />
</td>
</tr>
<% } %>
</table>
<input type="submit" value="Create"/>
<%} %>
我的控制器動作:參數字典包含參數無效項
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult OrderDevice(int id)
{
try
{
// TODO: Add insert logic here
orderdevice ord = new orderdevice();
ord.Id = System.Convert.ToInt32(Request.Form["Id"]);
ord.OrderId = System.Convert.ToInt32(Request.Form["OrderId"]);
ord.DeviceId = System.Convert.ToInt32(Request.Form["DeviceId"]);
XMLEntities.AddToorderdevice(ord);
XMLEntities.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View("Index");
}
}
當後一種形式我有這樣的錯誤:參數字典中包含的非參數「ID」無效項'MvcKVteam.Controllers.ImportXMLController'中方法'System.Web.Mvc.ActionResult OrderDevice(Int32)'的可空類型'System.Int32'。可選參數必須是引用類型,可爲空類型,或者聲明爲可選參數。 參數名稱:參數
如何解決?
Tnx丹尼爾,你解決我的問題 – Ognjen 2010-05-19 08:24:36