【问题标题】:@Ajax.Actionlink render partialview@Ajax.Actionlink 渲染局部视图
【发布时间】:2013-04-23 13:22:37
【问题描述】:

我正在尝试使用 Ajax.Actionlink 来呈现部分视图。但它只会将我重定向到部分视图。我还在 webconfig 中添加了:<add key="UnobtrusiveJavaScriptEnabled" value="true" />。有人吗?

我的 layout.cshtml Scripts.render 和脚本在 head 标签中。 Ajax.actionlink 和 div 在正文中

@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/Scripts/jqueries")
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>



@Ajax.ActionLink("Ajax Click", "Document","Home", new AjaxOptions { UpdateTargetId = "result", InsertionMode = InsertionMode.Replace })

<div id="result">

</div>

家庭控制器:

public PartialViewResult Document()
     {

                return PartialView("Document", om);
     }

我的文档.cshtml

@model mymodel


@foreach (var item in Model)
{ 
            <li>@Html.ActionLink(item.something, "Controller", "Action")</li>
 }

【问题讨论】:

    标签: ajax asp.net-mvc actionlink


    【解决方案1】:

    你的 jquery 和 unobtrusive-ajax 应该在页面底部,像这样

    </footer>
    @Scripts.Render("~/bundles/jquery")
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
    @RenderSection("scripts", required: false)
    </body>
    </html>
    

    信息为什么可以在这里找到 http://developer.yahoo.com/performance/rules.html/ 把它放在错误的地方,会导致错误

    【讨论】:

    • 会投票,但需要 15 名声望 :P 确实有效,谢谢!
    • 你能解释一下为什么它必须是这样的吗?每次我使用 javascript 时都需要这样做吗?
    • 信息为什么可以在这里找到developer.yahoo.com/performance/rules.html把它放在错误的地方,会导致错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多