How to call partial views (ajax based) directly on index page of a VIEW (MVC) with layout of index too

你。 提交于 2019-12-08 22:02:29

Change your @Html.ActionLink to @Ajax.ActionLink

<li>@Html.ActionLink("About Us", "Index", "AboutUs")
    <ul>
        <li>@Ajax.ActionLink("Vision & Misson", "VisionAndEthics", new AjaxOptions {
                InsertionMode = InsertionMode.Replace, UpdateTargetId = "divTarget"
            })</li>
        <li>@Ajax.ActionLink("Our Ethics", "OurEthics", new AjaxOptions {
                InsertionMode = InsertionMode.Replace, UpdateTargetId = "divTarget"
            })</li>
    </ul>
</li>

The insertion mode property is set to replace and the UpdateTargetId property is the id of the HTML container you want to put the result in.

Then in your controller

public PartialViewResult VisionAndEthics() {
    return PartialView("VisionAndMission");
}

public PartialViewResult OurEthics() {
    return PartialView("OurEthics");
}

This way you could also handle clients with javascript turned off by extending this solution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!