Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC3 Can two controller actions return one view?

I have two action methods in my controller. I want both to return one view.

The reason is because I have conditional checks in my view that checks if a property is null then don't show a div and if a user clicks on load button then the same view needs to be returned by setting the property of the model and then the div is shown.

This logic is required for atleast 15 times and I want to create separate actions that return the model but one view. Is it possible?

like image 492
InfoLearner Avatar asked Jan 08 '12 21:01

InfoLearner


1 Answers

You just have to state that view name in your return statement:

public ActionResult SomeAction()
{
    // do something
    return View("SharedView", viewModel);
}

If you have a view named SharedView, all actions in that controller can access it. If you want to share it among actions that are on other controllers, you can use the Shared folder in Views or state full path with the view name.

like image 164
Ufuk Hacıoğulları Avatar answered Nov 15 '22 18:11

Ufuk Hacıoğulları