Load partial view in main view on click

谁都会走 提交于 2020-01-21 08:55:54

问题


I'm trying to get a partial view to load on my current view when the user clicks the link but it keeps loading the partial view rather then on the same view.

Not sure what I'm missing.

Main View Controller

    public PartialViewResult MonitorDetail(MonitorType mType)
    {
        return PartialView("MonitorDetail", mType);
    }

Main View

<script src="~/Scripts/jquery-2.1.1.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>

<p class="lbutton radius">
    @Ajax.ActionLink("SQL Cluster Online ", "MonitorDetail", "NOCCon", MonitorType.AHSSQLCluster, new AjaxOptions() { UpdateTargetId = "monitorDetail" })
    <span class="lbutton-addition @(Model.SQLClusterOnline ? "online" : "offline")">
        @(Model.SQLClusterOnline ? "Online" : "Offline")
    </span></p>

<div id="monitorDetail"></div>

Partial View

@model PAL.Intranet.MonitorType
<div>
    You choose @Model.ToString()
</div>

Also keeps telling me mType is null but i'm passing it MonitorType in the ActionLink so I added it as nullable so I can try and figure out the first issue and then work on the second.


回答1:


If its displaying only the partial view, its because you have not included the required files for Ajax.ActionLink to work (and its just performing a normal redirect). Ensure you have included jquery.{version}.js and jquery.unobtrusive-ajax.js

The reason parameter mType is null is because you are not passing a value. It should be

@Ajax.ActionLink("SQL Cluster Online ", "MonitorDetail", "NOCCon", new { mtype = MonitorType.AHSSQLCluster }, new AjaxOptions() ....)


来源:https://stackoverflow.com/questions/29292189/load-partial-view-in-main-view-on-click

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