pass string from one action to other in same controller
-
27-10-2019 - |
Question
I am passing search string from Search action to detail action but on being received in detail action it turns out to be null.
I am using MVC3 and .NET framework 4.0:
public ActionResult Search(string search)
{
if (string.IsNullOrEmpty(search))
return RedirectToAction("Index");
return RedirectToAction("Details", "Invoice", search = search.Trim());
}
public ActionResult Details(string id)
{
if (string.IsNullOrEmpty(id))
return RedirectToAction("Index");
ObjectParameter[] parameters = new ObjectParameter[3];
parameters[0] = new ObjectParameter("CUSTNMBR", id);
parameters[1] = new ObjectParameter("StartDate", System.DateTime.Now.Date.AddDays(-90));
parameters[2] = new ObjectParameter("EndDate", System.DateTime.Now.Date);
return View(_db.ExecuteFunction<Models.Invoices>("uspGetCustomerInvoices", parameters).ToList<Models.Invoices>());
}
Solution
You should use:
return RedirectToAction("Details", "Invoice", new { id = search.Trim() });
OTHER TIPS
You should be able to just return Details() since you are in the same controller and it returns an ActionResult.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow