Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

jquery - How can I code a refresh of a HTML.RenderPartial using Ajax in MVC3?

I have the following view:

    @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);
    }

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need a child action, not a partial view.

You can then write

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...