我怎样才能code MVC3中使用Ajax HTML.RenderPartial的刷新? [英] How can I code a refresh of a HTML.RenderPartial using Ajax in MVC3?

查看:303
本文介绍了我怎样才能code MVC3中使用Ajax HTML.RenderPartial的刷新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下看法:

    @model ViewModels.Shared.BaseViewModel
    <div class="rep_tb0">
        <div class="rep_tr0">
            <div class="rep_td0">@Html.LabelFor(model => Model.Link.Position)</div>
            <div class="rep_td0">@Html.LabelFor(model => Model.Link.Title)</div> 
        </div>
        @for (var i = 0; i < Model.AdminDetails.Count; i++)
        {
            var qs = "&ac=" + Model.Meta.AccountID +
                     "&me=" + Model.AdminDetails[i].RowKey;  
        <div class="rep_tr0">
            <div class="rep_td0">
                @Html.TextBox(("Position_" + @i), Model.AdminDetails[i].Position, new { size = 2 })
            </div>
            <div class="rep_td0">@Model.AdminDetails[i].Title</div>             
        </div>  
        }
    </div>    

此控制器动作填充:

Populated by this controller action:

    public ActionResult Detail(string ac, string me)
    {
            vm.AdminDetails = _link.Detail(ac + me).ToList();
        return View(vm);
    }

我想使用Ajax,jQuery和HTML.Renderpartial因为有次当我需要的时候我改变位置的值来请求例如数据的刷新。

I would like to use Ajax, jQuery and HTML.Renderpartial as there are times when I need to request a refresh of the data for example when I change the value of position.

我完全新这样的想法。我发现,帮助我联系,但大多是关于Ajax与早期版本的MVC,而不是这么多关于MVC3。有人可以给我一些指点。我不是找code。只是,我怎么能去这样做的编码在我的操作方法,我应该怎么叫几号线为例阿贾克斯等。

I am totally new to the idea of doing this. I found links that help me but mostly it was about Ajax with earlier versions of MVC and not so much about MVC3. Can someone give me some pointers. I am not looking for code. Just a few line example of how I could go about doing the coding in my action method, how I should call the Ajax etc.

推荐答案

您需要一个孩子的行动,而不是一个局部视图。

You need a child action, not a partial view.

您可以接着写

<div id="#thingy">@Html.Action("Detail", new { ac, me })</div>

$('#thingy').load("@Server.JavaScriptStringEncode(Url.Action("Detail", new { ac, me }))");

这篇关于我怎样才能code MVC3中使用Ajax HTML.RenderPartial的刷新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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