我试图传递参数,即'priceValue'。我怎样才能通过使用RedirectToAction传递这个值?或者你有什么想法吗? 我正试着让购物车现在。 'priceValue'是radioButton的值。你能给我一些帮助吗?在传递了priceValue之后,我想用if语句写我在AddToCart中写的东西。可以使用它吗? 请帮我.. 谢谢。MVC3将参数传递给同一控制器中的其他人
public class ShoppingCartController : Controller
{
rentalDB db = new rentalDB();
//
// GET: /ShoppingCart/
public ActionResult Index()
{
var cart = ShoppingCart.GetCart(this.HttpContext);
// Set up our ViewModel
var viewModel = new ShoppingCartViewModel
{
CartItems = cart.GetCartItems(),
CartTotal = cart.GetTotal()
};
// Return the view
return View(viewModel);
}
// GET: /Store/AddToCart/5
[HttpPost]
public ActionResult AddToCart(int id, FormCollection col)
{
var addedProduct = db.Product
.Single(product => product.productId == id);
decimal priceValue = Convert.ToDecimal(col["price"]);
//how to pass priceValue to index
if (Convert.ToDecimal(col["price"]) == addedProduct.threeDayPrice)
{
ViewBag.price = new SelectList(db.Product, "productId", "threeDayPrice");
//How to put this value into cart.AddtoCart(addedProduct) with date and price
}
else if (Convert.ToDecimal(col["price"]) == addedProduct.aWeekPrice)
{
ViewBag.price = new SelectList(db.Product, "productId", "aWeekPrice");
//How to put this value into cart.AddtoCart(addedProduct) with date and price
}
// Retrieve the product from the database
// Add it to the shopping cart
var cart = ShoppingCart.GetCart(this.HttpContext);
cart.AddToCart(addedProduct);
// Go back to the main store page for more shopping
//I don't know how to pass the 'priceValue' by using RedirectToAction.
return RedirectToAction("Index", new {id = priceValue});
}
谢谢你的回复!我已经知道了。谢谢! – wholee1 2012-04-02 03:52:41