简体   繁体   English

单击时在主视图中加载局部视图

[英]Load partial view in main view on click

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.还一直告诉我 mType 为空,但我在 ActionLink 中将它传递给 MonitorType,所以我将其添加为可为空的,这样我就可以尝试找出第一个问题,然后处理第二个问题。

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).如果它只显示部分视图,那是因为您没有包含Ajax.ActionLink工作所需的文件(并且它只是执行正常的重定向)。 Ensure you have included jquery.{version}.js and jquery.unobtrusive-ajax.js确保您已包含jquery.{version}.jsjquery.unobtrusive-ajax.js

The reason parameter mType is null is because you are not passing a value.参数mType为 null 的原因是因为您没有传递值。 It should be它应该是

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM