2013-04-23 149 views
1

我想使用Ajax.Actionlink渲染局部视图。但它只会将我重定向到局部视图。我还添加了:<add key="UnobtrusiveJavaScriptEnabled" value="true" />到webconfig。任何人?@ Ajax.Actionlink渲染部分视图

我的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> 

Home控制器:

public PartialViewResult Document() 
    { 

       return PartialView("Document", om); 
    } 

我Document.cshtml

@model mymodel 


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

回答

5

你的jQuery和不显眼的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/ 在错误的地方放置这个发现,将导致错误

+0

会投票,但需要15reputation:P它没有工作,谢谢! – 2013-04-25 10:31:34

+0

你可以解释为什么它必须是这样吗?每次我使用JavaScript时,我都需要这个吗? – 2013-04-25 11:48:59

+0

信息为什么可以在这里找到http://developer.yahoo.com/performance/rules.html/把它放在错误的地方,将导致错误 – 2013-04-25 12:07:20