0

I have an index view that I want to update automatically as the user types in a client id. I got something similiar to work (only it was updating just a label) - but this will not work.

What happens is the partial is just rendered by itself (not in place of the UpdateTargetID). So the data is rendered on a new page. Here is my code:

Controller:

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

Partial View:

<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>

Main View:

Insert code messed up, so this is just copy/pasted:

$(function() { $("#queryText").keyup(function() { $('#sForm').submit(); }); });

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

  </div>
3
  • EDIT: (only it was updating just a label) Commented Jul 3, 2009 at 0:16
  • By the way I have visited jarrettatwork.blogspot.com/2009/02/… - great link with very useful information. Ive also done a lot of googling but still can't get it right. Commented Jul 3, 2009 at 0:35
  • Jack, I have the exact same problem. It should update the div but it doesn't. How did you manage to solve that problem? Thanks! Commented Jan 13, 2010 at 10:28

2 Answers 2

1

I had the same problem.

In my partial view, I had this

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

but it should have been this

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

an easy way to test if your ajax call is working is to return a string instead of an ActionResult

public string ClientList(string queryText)<
{
    return("ok, the ajax call must have worked because I see this string.");
}
Sign up to request clarification or add additional context in comments.

Comments

0

Rather than posting a form on the page constantly why not do a behind the scenes jQuery.get call to get the search results for the provided text. I would think this would be faster and cleaner. When submitting the form like I think you are (judging from my reading of your code) you are causing the page to essentially refresh (and not re-write to the div).

$('#sForm').submit()

2 Comments

How might I go about doing that? I've seen some examples of basic jQuery.get usage, but what is the syntax for passing the form data (from the text box)? Is it just simply $("#queryText").val(); ? I have not messed with json results at all.
You might find this article helpful! dotnetcurry.com/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.