문제

I am getting the following error when trying to return a ViewResult from a post action:

The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Home/Index.cshtml ~/Views/Shared/Index.cshtml ~/Views/Home/Home.cshtml
~/Views/Shared/Home.cshtml ~/Views/Home/Index.aspx
~/Views/Home/Index.ascx ~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx ~/Views/Home/Home.master
~/Views/Shared/Home.master ~/Views/Home/Home.vbhtml
~/Views/Shared/Home.vbhtml

My view is definitely recognised because it works on the GET action.

The code that returns the ViewResult in the POST action is:

return View("Index", "Home", Model);

Here is the view.

Can anybody suggest why this would not be working?

A little more context: The get action displays the view fine. The post action is actually to a different url but returns the same view. It's the post action that's causing the problem. Both GET and POST actions are on the same controller HomeController.

Here's the (stripped down) controller:

public class HomeController : Controller
{
    [HttpGet]
    public ActionResult Index()
    {
        return View(new LoginModelBase());
    }

    [HttpPost]
    public ActionResult Login(UsernameLoginModel Model)
    {
        ...
        return View("Index", "Home", Model);
    }
}
도움이 되었습니까?

해결책

I've just realised what it is!. I'm using the wrong overload of the View(...) method.

It should be:

View("Index", Model);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top