I'm trying to send a string Id from
one action in one controller to
another action in another controller using RedirectToAction() but i keep getting a null reference exception:
This is the error: Object reference not set to an instance of an object.
RedirectToAction() method i'm using:
return RedirectToAction("Index", "Assignments", new { cid = id.ToString() });
the http request i'm getting:
http:/localhost:13501/Assignments?cid=CAIS132
instead of this:
http:/localhost:13501/Assignments/index/CAIS132 Knowing that this works
Here's the first Action:
public ActionResult ManageCourse(object id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
return RedirectToAction("Index", "Assignments",new{cid=id.ToString()});
}
And here's my other action:
public ActionResult Index(string id)
{
return View(model);
}
and here's my RouteConfig.cs:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
The id attribute in the Index action is received null! Any ideas?
What I have tried:
I've tried a couple of thing and i cannot seem to find a solution for it!!
Please do anyone have any idea?
and when I use this:
return RedirectToAction("Index", "Assignments", id.ToString());
<I get this url with a NullReference:
http:/localhost:13501/Assignments?Length=7