I have a method SendMail in the MVC Controller.This method calls other method ValidateLogin. This is the signature of the Validate Login:
private ActionResult ValidateLogin(Models.ResetPassword model)
When I call the ValidateLogin from SendMail, this exception appears because the controller try to search a view SendMail, but I want to load the ResetPassword View:
Global Error - The view 'SendMail' or its master was not found or no view engine supports the searched locations. The following locations were searched: ...
This is the code of the SendMail:
public ActionResult SendMail(string login) { return ValidateLogin(login); }
How Can I override the View on the return statement?
Thanks in advance
Just add your View to the Shared subdirectory and you're good to go. If you do return View("~/Views/Wherever/SomeDir/MyView. aspx") You can return any View you'd like.
When you set Action's return type ActionResult , you can return any subtype of it e.g Json,PartialView,View,RedirectToAction.
Index(). ViewData. Model; If your method signature's return type is ActionResult instead of ViewResult, you will need to cast it to ViewResult first.
In ASP.NET Core MVC, a controller's ViewResult is capable of returning either a view or a partial view. In Razor Pages, a PageModel can return a partial view represented as a PartialViewResult object. Referencing and rendering partial views is described in the Reference a partial view section.
private ActionResult SendMail(string login) { return View("~/Views/SpecificView.cshtml") }
You can directly point towards specifc view by pointing to their location explicitly ..
finally, this was the solution
return View("ResetPassword", new ResetPassword { fields= fields });
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