1

尝试从发布操作返回 ViewResult 时出现以下错误:

未找到视图“索引”或其主视图,或者没有视图引擎支持搜索的位置。搜索了以下位置:~/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.vbhtml
~/Views/Shared/Home.vbhtml

我的观点肯定得到认可,因为它适用于 GET 操作。

在 POST 操作中返回 ViewResult 的代码是:

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

这是视图

任何人都可以建议为什么这不起作用?

更多上下文:get 操作可以很好地显示视图。post 操作实际上是针对不同的 url 但返回相同的视图。这是导致问题的发布操作。GET 和 POST 操作都在同一个控制器上HomeController

这是(精简的)控制器:

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

    [HttpPost]
    public ActionResult Login(UsernameLoginModel Model)
    {
        ...
        return View("Index", "Home", Model);
    }
}
4

1 回答 1

2

我刚刚意识到它是什么!我使用了错误的View(...)方法重载。

它应该是:

View("Index", Model);
于 2012-10-16T11:01:08.627 回答