单击时在主视图中加载局部视图 [英] Load partial view in main view on click

查看:32
本文介绍了单击时在主视图中加载局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击链接时,我试图在当前视图上加载分部视图,但它一直加载分部视图,而不是在同一视图上.

不确定我错过了什么.

主视图控制器

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

主视图

<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script><p class="lbutton 半径">@Ajax.ActionLink("SQL Cluster Online ", "MonitorDetail", "NOCCon", MonitorType.AHSSQLCluster, new AjaxOptions() { UpdateTargetId = "monitorDetail" })<span class="lbutton-addition @(Model.SQLClusterOnline ? "online" : "offline")">@(Model.SQLClusterOnline ?在线":离线")</span></p><div id="monitorDetail"></div>

部分视图

@model PAL.Intranet.MonitorType<div>你选择@Model.ToString()

还一直告诉我 mType 为空,但我在 ActionLink 中将它传递给 MonitorType,因此我将其添加为可为空的,这样我就可以尝试找出第一个问题,然后处理第二个问题.

解决方案

如果它只显示部分视图,那是因为您没有包含 Ajax.ActionLink 工作所需的文件(及其只是执行正常的重定向).确保您已包含 jquery.{version}.jsjquery.unobtrusive-ajax.js

原因参数 mType 为 null 是因为您没有传递值.应该是

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

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.

解决方案

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() ....)

这篇关于单击时在主视图中加载局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆