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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With