asp.net-mvc - 未找到局部 View 'First.cshtml' 或没有 View 引擎支持搜索的位置

标签 asp.net-mvc asp.net-mvc-4 razor partial-views asp.net-mvc-ajax

我试图在点击时调用 div 中的部分 View 。我写过这个:

@Ajax.ActionLink("Second", "Second", new AjaxOptions()
{
    HttpMethod = "GET",
    UpdateTargetId = "partials",
    InsertionMode = InsertionMode.Replace
})

<div id="partials">
</div>

<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/additional-methods.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/mvc/5.2/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>

在我的 Index.cshtml.我的 Controller 看起来像这样:
public ActionResult Index()
        {
            return View();
        }

        public PartialViewResult Second()
        {

            return PartialView("Second.cshtml");
        }

但我的错误是在以下位置找不到我的部分 View :
~/Views/switchPartial/Second.cshtml.aspx
~/Views/switchPartial/Second.cshtml.ascx
~/Views/Shared/Second.cshtml.aspx
~/Views/Shared/Second.cshtml.ascx
~/Views/switchPartial/Second.cshtml.cshtml
~/Views/switchPartial/Second.cshtml.vbhtml
~/Views/Shared/Second.cshtml.cshtml
~/Views/Shared/Second.cshtml.vbhtml

但我在 switchPartial 文件夹。

如果我写 @Html.Partial("Second")在我的 div 中,它正确呈现了我的部分 View 。

我做错了什么?

最佳答案

无需在部分名称的末尾包含文件扩展名。尝试:

return PartialView("Second");

通过不包括文件扩展名,每个注册 ViewEngines有机会解析请求的 View (在 Second.cshtmlSecond.vbhtmlSecond.aspx 中)。

关于asp.net-mvc - 未找到局部 View 'First.cshtml' 或没有 View 引擎支持搜索的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28670738/

相关文章:

asp.net-mvc - ie9 : annoying pops-up while debugging: "Error: ' __flash__removeCallback' is undefined"

c# - ModelState.Clear 不工作

javascript - 将所有内容都返回 1 个 json 好吗?

c# - MVC 路由去掉 URL 中的/Index

angularjs - 使用 Angularjs 对可编辑行表单进行验证

c# - 从数据库中获取数据并使用 View 模型将其传递给 View

asp.net-mvc-4 - 混合使用MVC和Web API错误处理

asp.net-mvc - 将搜索集成到 ASP.NET MVC 站点的 header /母版页中

jquery - 如何使用 javascript 函数调用 MVC 中的 URL 操作?

c# - 在 View 中使用 expando 对象?