Reputation: 91
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
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
Reputation: 9598
You can specify the view name to return:
public ActionResult someAction()
{
return View("Index");
}
Upvotes: 2
Reputation: 22864
public ActionResult someAction()
{
return View("Index"); //How to make this action return Index.cshtml??
}
Upvotes: 1