I hava a View Name "Message" in the Jobs folder of Views. And I want to return that view form an action of different controller, named "MarketController"
public class MarketController : Controller
{
[HttpPost]
public ActionResult Save()
{
// logic to save the record
TempData["message"] = "Save successfully";
return View("Message");
}
}
The problem is that the "Message" view is not in the View of Market, how can i return that view from MarketController.
(I do not want to use RedirectToaction method here.)
In MVC we cannot pass multiple models from a controller to the single view.
In this example, we have created a sample login page, and based on Login we are redirecting to another controller action method. Open Visual Studio. Click on the file in the menu and select new Project . Select new project type.
Just use a relative path based on the Views
folder
return View("~/Views/Jobs/Message.cshtml");
You have to fill the full address for your Message view ("~/Views/Jobs/Message.cshtml"):
[HttpPost]
public ActionResult Save()
{
TempData["message"] = "Save successfully";
return View("~/Views/Jobs/Message.cshtml");
}
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