我有下面的代碼發送在MVC4
public ActionResult Item_Post()
{
List<Product> products=new List<Product>() ;
int? total=0;
HttpCookie cookie= Request.Cookies["myvalue"];
if (Request.Cookies["myvalue"] != null)
{
int count = Request.Cookies["myvalue"].Values.Count;
var s = Request.Cookies["myvalue"].Value;
s = HttpUtility.UrlDecode(s ?? string.Empty);
string[] values = s.Split(',').Select(x => x.Trim()).ToArray();
for (int i = 1; i < values.Length; i++)
{
int id = Convert.ToInt32(values[i]);
Product product = db.Products.Single(x => x.Id == id);
total+=product.Price;
products.Add(product);
}
ViewBag.total = total;
TempData["products"]=products;
}
Session["prod"] = products;
return View("Buy", products);
//return RedirectToAction("Buy");
}
現在使用RedirectToAction列表時,我只用返回視圖(「買入」,產品),我得到的輸出和我想要的網址仍然是相同的更改網址,當我使用
return RedirectToAction("Buy", products);
我收到錯誤,因爲我想發佈表單購買。參數在RedirectToAction中傳遞是否合適,或者是否需要其他參數。 這裏是行動
@model IEnumerable<Shop_Online.com.Models.Product>
@{
ViewBag.Title = "Buy";
}
@using (Html.BeginForm())
{
<div style="width: 860px; margin: 0 auto" class="main">
<table border="1" style="font-family: Verdana; font-size: 13px">
<tr style="background-color: #f2f2f2">
<th colspan="4">ITEM</th>
<th>DELIEVERY DETAILS</th>
<th>QTY</th>
<th>SUB TOTAL</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td colspan="4" style="width: 46%">
<table style="font-family: Verdana; font-size: 13px">
<tr>
<td>
<img src="@Url.Content(item.Photo)" alt="Image" style="width:36px" />
</td>
<td>
@Html.DisplayFor(x => item.Model_Name)
</td>
</tr>
<tr>
<td style="color: #ccc">30 days Replacement</td>
</tr>
</table>
</td>
<td style="width: 39%">Free Delievery Delivered in 2-3 business days.</td>
<td style="width: 5%">1</td>
<td style="width: 50%"><b>Rs. @Html.DisplayFor(x => item.Price)</b></td>
</tr>
}
</table>
<div style="width: 100%; height: 70px; background-color: #f2f2f2">
<div style="width: 75%; height: 70px; float: left; font-family: Verdana; font-size: 13px">
</div>
<div style="width: 25%; height: 70px; float: left; font-family: Verdana; padding-top: 20px; font-size: 13px">
Estimated Price: <b>[email protected]</b>
</div>
</div>
<div class="order" style="width: 100%; height: 70px">
<div class="left-order" style="width: 75%; height: 70px; float: left"></div>
<div class="left-order" style="width: 25%; float: left; height: 70px">
<input type="button" value="PLACE ORDER" style="border: 1px solid #ec6723; width: 216px; cursor: pointer; height: 45px; color: #fff; background: -webkit-linear-gradient(top,#f77219 1%,#fec6a7 3%,#f77219 7%,#f75b16 100%)" onclick="return confirm('Successfull placed order')" />
</div>
</div>
</div>
}
現在我應該怎麼替換我的視圖中的下面的代碼如果我使用TempData的
@foreach(var item in Model)
{
@Html.DisplayFor(model=>model.Name
/some more code/
}
PLZ評論,如果有不清楚的地方 – User
http://stackoverflow.com/questions/1257482/redirecttoaction-with-parameter – ssilas777
@ ssilas777因爲我傳遞值 – User