Nathiel Paulino
Nathiel Paulino

Reputation: 544

How to return a view from a different action in ASP.NET MVC

I have a view called DetailsLane and another AddItem. When the DetailsLane is rendered, it returns a model class with properties. The AddItem action is inside of the same controller, but when I finish whatever I had to do inside of this action, I can't re-render the DetailsLane to update the view.

The view is called first time: it works!

public ActionResult DetailsLane(int? id, int? IdInstance)
{
    return View(get(IdInstance, id));
}

public ActionResult AddLine(FormCollection collection)
{
      // I did my stuff in here, and I want to return the initial View or,
      // validate something from the collection.
      return DetailsLane(val, val);     // doesn't work!
}

Upvotes: 0

Views: 689

Answers (1)

egnomerator
egnomerator

Reputation: 1105

You want to use RedirectToAction and you can pass arguments as shown here

public ActionResult AddLine(FormCollection collection)
{
  // I did my stuff in here, and I want to return the initial View or,
  // validate something from the collection.
  return RedirectToAction("DetailsLane", new { id = val1, IdInstance = val2 });
}

note that id and IdInstance match the parameter names in your DetailsLane action method.

Upvotes: 2

Related Questions