5

I'm trying to call partial view in div on click. I've written this:

@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>

In my Index.cshtml. my controller looks like this:

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

        public PartialViewResult Second()
        {

            return PartialView("Second.cshtml");
        }

but my error says that my partial view can't found in:

~/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

but I have it in switchPartial folder.

If I write @Html.Partial("Second") in my div it renders correctly my partial view.

What have I done wrong?

4

1 回答 1

6

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

return PartialView("Second");

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

于 2015-02-23T09:46:59.080 回答