使用Ajax的部分视图 [英] Partial view using Ajax

查看:100
本文介绍了使用Ajax的部分视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在局部视图中绑定一个网格,但是当我这样做时整个浏览器都会轻弹



这是我调用我的控制器的地方



@ Html.Action(GridView1Partial)







这是我的控制器,我称之为GridView1Partial视图

  public  ActionResult GridView1Partial()
{
var model = db.People;
return PartialView(& amp; quot; _GridView1Partial& amp; quot;,model.ToList());
}





在_GridView1Partial中我编写了绑定网格的代码



如何通过仅更新网格部分来避免页面轻弹。我听说过@ Ajax.ActionLink。任何人都可以告诉我如何实现这个。



提前谢谢

解决方案

Hello id-athul;



上周日我有同样的问题,但我意识到我没有添加javascript引用来处理它。



在_Layout视图中尝试此操作

< script href =@ Url.Content(〜/ Scripts / jquery.unobtrusive-ajax.min.js)type =text / javascript >< / script> 





希望这有帮助?


嘿,



在布局中添加脚本引用



< script href =@ Url.Content(〜 /Scripts/jquery.unobtrusive-ajax.min.js)type =text / javascript>< / script>



并添加Ajax.ActionLink如下所示。



 Ajax.Actionlink( < span class =code-string> linkText,  Gr idViewPartial  ControllerName new  {}, new  AjaxOptions(){UpdateTargetId =   DivId,InsertionMode = InsertionMode.Replace})





确定这会有所帮助。 ;)


Hi,

I am binding a grid in a partial view,But when i do this the whole browser is flicking

This is where i call my Controller

@Html.Action(GridView1Partial)



This is my Controller where i call the view "GridView1Partial"

public ActionResult GridView1Partial()
       {
           var model = db.People;
           return PartialView(&amp;quot;_GridView1Partial&amp;quot;, model.ToList());
       }



And in _GridView1Partial i have written the code to bind the grid

How can i avoid page flicking by updating just the grid part.I have heard about @Ajax.ActionLink. Can anyone tell me how to implement this.

Thanks in advance

解决方案

Hello id-athul;

I have this same issue last Sunday but I realized I didn't add a javascript references to handle that.

Try this in your _Layout view

<script href="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

.

Hope this helps?


Hey,

Add the script reference in layout

<script href="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

And add Ajax.ActionLink as follows in your case.

Ajax.Actionlink("linkText","GridViewPartial","ControllerName",new{},new AjaxOptions(){UpdateTargetId="DivId",InsertionMode = InsertionMode.Replace})



Dam sure this will help. ;)


这篇关于使用Ajax的部分视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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