我有希望作为在客户端ID的用户类型的自动更新索引视图。我有类似的东西的工作(只有它正在更新只是一个标签) - 但这是行不通的。

所发生的是该部分仅通过自身呈现(不到位UpdateTargetID的)。因此,数据呈现一个新的页面上。这是我的代码:

控制器:

public ActionResult ClientList(string queryText)
    {
        var clients = CR.GetClientLike(queryText);
        return PartialView("ClientIndex", clients);
    }

局部视图:

<table>
<thead>
    <tr>
        <td>Client ID</td>
        <td>Phone1</td>
        <td>Phone2</td>
        <td>Phone3</td>
        <td>Phone4</td>
    </tr>
</thead>
<tbody>
    <% if (Model != null)
       {
           foreach (Client c in Model)
           { %>
        <tr>
            <td><%= Html.Encode(c.ClientID)%></td>
            <td><%= Html.Encode(c.WorkPhone)%></td>
            <td><%= Html.Encode(c.WorkPhone1)%></td>
            <td><%= Html.Encode(c.WorkPhone2)%></td>
            <td><%= Html.Encode(c.WorkPhone3)%></td>

        </tr>
    <% }
       } %>
</tbody>

主视图:

插入代码弄乱,所以这只是复制/粘贴:

             $(函数(){             $( “#QUERYTEXT”)。KEYUP(函数(){                 $( '#sForm')提交()。             });         });     

                 
  <div id="status" class="status" name="status">
    <%--<% Html.RenderPartial("ClientIndex", ViewData["clients"]); %> Should this be here???? --%>

  </div>
有帮助吗?

解决方案

而不是张贴页面上的表单不断为什么不能做一个幕后jQuery.get呼吁以获取所提供的文本搜索结果。我认为这将是更快,更清洁。当提交表单就像我认为你(从我读你的代码的判断),你是导致页面基本上刷新(而不是重新编写到div)。

$('#sForm').submit()

其他提示

我有同样的问题。

在我的局部视图,我有这个

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

,但它应该已经此

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IQueryable<Client>>" %>

一个简单的方法来测试,如果你的Ajax调用的工作是返回一个字符串,而不是一个ActionResult

public string ClientList(string queryText)<
{
    return("ok, the ajax call must have worked because I see this string.");
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top