开发者

Value not passing when redirecting from controller to another controller while passing data in MVC 2

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");
}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜