我正试图在点击时调用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")
,它会正确呈现我的部分视图。
我做错了什么?
答案 0 :(得分:5)
无需在部分名称的末尾包含文件扩展名。尝试:
return PartialView("Second");
如果不包含文件扩展名,则每个已注册的ViewEngines
都有机会解析所请求的视图(位于Second.cshtml
,Second.vbhtml
或Second.aspx
)。