【问题标题】:how to call Partialview inside another view in asp.net mvc如何在asp.net mvc的另一个视图中调用Partialview
【发布时间】:2016-08-24 12:25:33
【问题描述】:

如果我单击“执行”按钮,我会将我的操作重定向到 viewpage(GetSection),在此页面中,partialview(CoverPage) 应该在没有任何事件的情况下自动呈现,它具有导航栏,CoverPage 也是导航栏的一部分,所有导航栏值都来了从数据库中,我尝试了 "@Html.RenderPartial("CoverPage")" 语法,但它对我不起作用,这是我的查看页面

<table style="width:auto">
    @foreach (Test_Section p in Model)
    {
        <tr>
            <td>
                <div id="ajaxnav" class="navbar-left">
                    <ul class="nav nav-pills nav-stacked">
                        <li class="navigationLink">
                   @Ajax.ActionLink(p.SectionName, p.Title, new { id = p.StdSectionId },
                   new AjaxOptions
                   {
                       UpdateTargetId = "getHtml",
                       InsertionMode = InsertionMode.Replace,
                       HttpMethod = "GET"
                   }, new { style = "color:black" , @class = "navigationLink" })


                        </li>
                    </ul>
                </div>
            </td>
        </tr>

    }
    <div id="getHtml" class="divhtml"></div>
</table>

控制器是

public ActionResult GetSections()
        {
            Test_Section[] section = context.Test_Section.ToArray();
            return PartialView(section);
        }

所以请帮帮我。

【问题讨论】:

  • 你在哪里调用局部视图?你试过@Html.Partial("CoverPage")
  • 在 ajax .actionlink 中,我从数据库(导航栏)中提取所有部分视图链接。还有我想显示任何1个部分视图
  • 你说你想在没有任何事件的情况下加载部分视图。但现在你说你想要它与 ajax 动作链接。你能用明确的信息更新你的问题吗?
  • 我有 GetSection 操作,在这里我使用 Ajax 从数据库中提取所有部分视图链接,在这里我想在从数据库检索的链接上没有任何点击事件的第一个部分视图

标签: ajax redirect asp.net-mvc-5 rendering partial-views


【解决方案1】:

从您的 cmets 看来,您希望加载页面加载时第一个链接的点击事件的响应。

您可以使用 jquery trigger 方法触发链接点击文档就绪事件。

$(function () {

    if ($("a.navigationLink").length) {
       $("a.navigationLink").eq(0).trigger( "click" );
    }

});

【讨论】:

  • 如何为导航栏的第一个链接选择或应用 CSS
  • $("a.navigationLink").eq(0) 是第一个链接(包装的 jquery 对象)。您可以将 css 类应用于类似 `$("a.navigationLink").eq(0).addClass("yourCssClassName") 或使用 jquery css 方法
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-16
  • 1970-01-01
  • 2015-09-14
相关资源
最近更新 更多