为什么局部视图在同一个页面未呈现? (ASP.NET MVC 4) [英] Why partial view not rendering in the same page? (ASP.NET MVC 4)

查看:190
本文介绍了为什么局部视图在同一个页面未呈现? (ASP.NET MVC 4)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,局部视图中显示。

I've faced a problem for partial view displaying.

    //This is Controller Action 
//_AcademicInfo is the Partial view name
public PartialViewResult GetAcademicInfo(int empId)
        {
            var acad = _academicService.GetAcademinByEmp(empId);
            return PartialView("_AcademicInfo", acad);
        }

<!--Parent/caller page cshtml code-->

@Ajax.ActionLink(
            "Academic Details",
            "GetAcademicInfo",
            "Employee", new {empId = Model.Id},
            new AjaxOptions {UpdateTargetId = "AcademicDetails", InsertionMode = InsertionMode.InsertAfter}
            )

 <!--This is partial view cshtml-->
@model IEnumerable<Hik.PhoneBook.Data.Entities.Academic>

<div id="result">

    <table>
        <tr>
            <th>Degree Name</th>
            <th>Passing Year</th>
            <th>CGPA</th>
            <th>Institute</th>
        </tr>


        @foreach (var acad in Model)
        {
            <tr>
                <td>@Html.DisplayFor(m => acad.DegreeName)</td>
                <td>@Html.DisplayFor(m => acad.PassingYear)</td>
                <td>@Html.DisplayFor(m => acad.CGPA)</td>
                <td>@Html.DisplayFor(m => acad.Institute)</td>
            </tr>
        }

    </table>

</div>

作为,因为我需要通过点击链接来获得局部视图,而不是直接呈现像 @ Html.Partial(_ AcademicInfo,Model.Academic)。这就是为什么我用Ajax.ActionLink。每当我点击学术细则链接,其执行准确的结果。但不幸的是它不是在同一个页面中显示。它会出现在另一页。 (其MVC 4)

As because, I need to get the partial view by a Link clicking, not by rendering directly like @Html.Partial("_AcademicInfo", Model.Academic). Thats why I've used Ajax.ActionLink. Whenever I click on "Academic Details" link, its executing the accurate result. But unfortunately its not displaying in the same page. Its going to appear in another page. (Its MVC 4)

我应该需要改变呈现在同一页面的局部视图?

推荐答案

如果您重定向到一个新的页面,而不是停留在同一页上,这意味着 jquery.unobtrusive-ajax.js 未加载和 @ Ajax.ActionLink()回落到一个正常的链接。

If you are redirecting to a new page rather than staying on the same page, it means that jquery.unobtrusive-ajax.js is not loaded and @Ajax.ActionLink() falls back to a normal link.

要么你要么


  1. 不包含脚本

  2. 已经在错误的顺序执行这些脚本( {jQuery的版本} .js文件一定要来
    第一)

  3. 您有重复的脚本

这篇关于为什么局部视图在同一个页面未呈现? (ASP.NET MVC 4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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