我想創建一個購物車,但在嘗試ID傳遞,因爲這一種說法是發生什麼事MVC傳遞屬性作爲參數
http://localhost:15359/RealCartController/Order/FinalProject.Models.Clothes
HTTP錯誤404.0 - 找不到 你正在尋找的資源已被刪除,名稱已更改或暫時不可用。
這是RealCartController
public ActionResult Order(int id)
{
if(Session["cart"] == null)
{
List<Item> cloth = new List<Item>();
cloth.Add(new Item(de.Clothes.Find(id),1));
Session["cart"] = cloth;
}
else
{
List<Item> cart = (List<Item>)Session["cart"];
int index = isExisting(id);
if (index == -1)
cart.Add(new Item(de.Clothes.Find(id), 1));
else
cart[index].Amount++;
Session["cart"] = cart;
}
return View();
}
這是在調用該函數
@if (Model != null)
{
foreach (Clothes Id in Model)
{
if (Id.Amount > 0)
{
<div id="container">
<div id="row">
<img src="~/Content/img/@Html.DisplayFor(model => Id.ImagePath)" style="height:200px;width:200px;" />
<br />
<br />
@Html.ActionLink("Add To Cart", "Order", "RealCartController", new { id = Id }, null);
</div>
</div>
}
}
}
查看這是函數
@foreach (Item item in (List<Item>)Session["cart"])
{
<tr>
<td>@item.Cl.Id</td>
<td>@item.Cl.Price</td>
<td>@item.Cl.Amount</td>
<td>@item.Cl.Price * item.Cl.Amount</td>
</tr>
}
我確認鏈接提供的項目的主鍵給出了404錯誤:=) –
鏈接指向位於本地計算機上的* localhost *。如果我們沒有配置設置或文件位於我們的機器中,我們無法測試它的有效性。 : - \ – Sometowngeek
@LaurentLequenne和Sometowngeek將它自動格式化爲一個鏈接,並且URL中的信息是相關的。 – NtFreX