Is it possible to pass data from one controller to another? When my second controller is called the int id is showing the WRONG value:
I have one controller:
public ActionR开发者_运维技巧esult Index(int id)
{
return RedirectToAction("New", "NewProducts", id);
}
NewProductsController:
public string New(int id)// <--------id never has correct number when called
{
return "value: " + id;
}
You need to use either a RouteValueDictionary or an anonymous type with an id property for the route values otherwise it will use the properties on the Int32
object id
to fill the route values dictionary.
public ActionResult Index(int id)
{
return RedirectToAction("New", "NewProducts", new { id = id } );
}
Hope it will work
public ActionResult Index(int id)
{
return RedirectToAction("New?id=" + id, "NewProducts");
}
精彩评论