如何在ASP.NET MVC更新面板 [英] How to make update panel in ASP.NET MVC

查看:102
本文介绍了如何在ASP.NET MVC更新面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在 ASP.NET模型视图位指示(MVC) 框架?

推荐答案

您可以使用在ASP.NET MVC中的部分观点得到类似的行为。局部视图仍然可以建立在服务器上的HTML,你只需将HTML插入正确位置(实际上,MVC阿贾克斯佣工可以,如果你愿意为包括MSFT Ajax库为您设置此)。

You could use a partial view in ASP.NET MVC to get similar behavior. The partial view can still build the HTML on the server, and you just need to plug the HTML into the proper location (in fact, the MVC Ajax helpers can set this up for you if you are willing to include the MSFT Ajax libraries).

在主视图中您可以使用Ajax.Begin形式来设置非同步请求。

In the main view you could use the Ajax.Begin form to setup the asynch request.

    <% using (Ajax.BeginForm("Index", "Movie", 
                            new AjaxOptions {
                               OnFailure="searchFailed", 
                               HttpMethod="GET",
                               UpdateTargetId="movieTable",    
                            }))

       { %>
            <input id="searchBox" type="text" name="query" />
            <input type="submit" value="Search" />            
    <% } %>

    <div id="movieTable">
        <% Html.RenderPartial("_MovieTable", Model); %>
   </div>

一个局部视图封装了要更新页面的部分。

A partial view encapsulates the section of the page you want to update.

<%@ Control Language="C#" Inherits="ViewUserControl<IEnumerable<Movie>>" %>

<table>
    <tr>       
        <th>
            Title
        </th>
        <th>
            ReleaseDate
        </th>       
    </tr>
    <% foreach (var item in Model)
       { %>
    <tr>        
        <td>
            <%= Html.Encode(item.Title) %>
        </td>
        <td>
            <%= Html.Encode(item.ReleaseDate.Year) %>
        </td>       
    </tr>
    <% } %>
</table>

然后设置你的控制器动作来处理这两种情况。局部视图结果与asych要求效果很好。

Then setup your controller action to handle both cases. A partial view result works well with the asych request.

public ActionResult Index(string query)
{          
    var movies = ...

    if (Request.IsAjaxRequest())
    {
        return PartialView("_MovieTable", movies);
    }

    return View("Index", movies);      
}

希望有所帮助。

Hope that helps.

这篇关于如何在ASP.NET MVC更新面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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