user3493623
user3493623

Reputation: 91

How to return an existing view from a new action in ASP.NET MVC 4?

Noob needs help!) How can I return an existing view from a new action within the same controller? For example I have a following code:

[HttpGet]
public ActionResult Index()
{
     return View(); //returns Index.cshtml
}

[HttpPost]
public ActionResult Index(string id, string condition)
{
     SomeModel.ID = id;
     SomeModel.Condition = condition;
     return View(SomeModel); //returns Index.cshtml delegating the model
}

public ActionResult someAction()
{
     return View(); //How to make this action return Index.cshtml??
}

Upvotes: 0

Views: 4793

Answers (3)

kevinkrs
kevinkrs

Reputation: 108

Just add

return View("YourView");

If you want send a model to it you can do this

var model = new YourViewModel {

}

return View("YourView", model);

Upvotes: -2

eouw0o83hf
eouw0o83hf

Reputation: 9598

You can specify the view name to return:

public ActionResult someAction()
{
     return View("Index"); 
}

Upvotes: 2

blorkfish
blorkfish

Reputation: 22864

public ActionResult someAction()
{
     return View("Index"); //How to make this action return Index.cshtml??
}

Upvotes: 1

Related Questions