Reputation: 1323
I want to be able to use the value of a string variable passed to one ActionResult, within another ActionResult.. How could i go about doing this?
public ActionResult PassCategoryPlaceHolder(string placeHolder)
{
var result = placeHolder;
return RedirectToAction("EditCategory", result);
}
I want to be able to use 'result' in my other ActionResult as follows:
public ActionResult EditCategory()
{
ViewBag.Message = Convert.ToString(result);
return View();
}
Note: I am trying to avoid sending 'placeHolder' directly to the ActionResult where i need it.
Upvotes: 0
Views: 1736
Reputation: 61
Simply use a Session variable:
public ActionResult PassCategoryPlaceHolder(string placeHolder)
{
Session["result"] = placeHolder;
return RedirectToAction("EditCategory");
}
public ActionResult EditCategory()
{
var Message = Convert.ToString(Session["result"]);
return View();
}
Upvotes: 2
Reputation: 1381
You can do something like this
public ActionResult PassCategoryPlaceHolder(string placeHolder)
{
var result = placeHolder;
return RedirectToAction("EditCategory", new { message = result});
}
And in other method:-
public ActionResult EditCategory(string message)
{
var model = new EditCategoryViewModel();
model.Message = message;
return View(model);
}
Upvotes: 2