asp.net-mvc – 未找到部分视图“First.cshtml”或视图引擎不支持搜索的位置

我试图在点击时调用div中的局部视图.我写过:

@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中.我的控制器看起来像这样:

public ActionResult Index()
        {
            return View();
        }

        public PartialViewResult Second()
        {

            return PartialView("Second.cshtml");
        }

但我的错误说我的部分视图无法找到:

~/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文件夹中有它.

如果我在我的div中写@ Html.Partial(“Second”)它会正确呈现我的局部视图.

我做错了什么?

解决方法

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

return PartialView("Second");

通过不包括文件扩展名,每个注册的ViewEngines都有机会解析所请求的视图(在Second.cshtml,Second.vbhtml或Second.aspx中).

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....