5

I am using MVC3 and displaying my data in a webgrid. I would like to display loading indicator (loading image) displayed when I filter/search. What is the best approach?

My search filter (code):

@using (Html.BeginForm())
{
     <fieldset  id="fieldset1" class="coolfieldset">

        <legend>Search for Towers Watson Subscribers/Contacts</legend>
        <div class="div-table">
        <div class="div-table-row">
            <div class="div-table-col">Reg Date:</div>
            <div class="div-table-col"><input id="regDateFrom" class="datepicker" name="regDateFrom" value="@regDateFrom" type="text" /> to <input id="regDateEnd" class="datepicker" value="@regDateEnd" name="regDateEnd" type="text" /></div>
        </div>
        <div class="div-table-row">
            <div class="div-table-col">Profile Mod Date:</div>
            <div class="div-table-col"><input type="text" id="profileModDateFrom" class="datepicker" value="@profileModDateFrom"  name="profileModDateFrom" /> to <input id="profileModDateEnd" class="datepicker" value="@profileModDateEnd" name="profileModDateEnd" type="text" /></div>
        </div>
        <div class="div-table-row">
            <div class="div-table-col">Last Name:</div>
            <div class="div-table-col"><input type="text" id="lastName" name="lastName" value="@lastName" /></div>
        </div>
          <div class="div-table-row">
            <div class="div-table-col"><input id="search" name="search" type="submit" value="Search" /></div>
            <div class="div-table-col"></div>
        </div>
        </div>      
    </fieldset>
}
{@Html.Partial("List_Ajax", Model)}

1 Answer 1

6

http://www.ajaxload.info/ lets you create a nice loading gif. Create an image, and place it in a div as below. Then bind the search button with jQuery to display the hidden div when clicked.

Place the following div where you would like the loading icon to appear.

<div id="loadingDiv" style="display:none"><img src="loading.gif"></div>

Then this in your Javascript file

$(document).ready(){
    $('#search').click(function(){
        $('#loadingDiv').show();
    });
});

Then when you're done loading, simply:

function SomeCallBackEvent(){
    $('#loadingDiv').hide();
};
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, exactly what I needed!
@RyanAmies For us n00bs here, how does one generally know when loading is complete given that items are being added to the grid? Could you provide a simple example to extend this answer? Thank you.
It really depends on your code. If you're loading it with jQuery/Ajax then you will have a callback for Complete which you can leverage. If you're stuck I'd suggest posting a new question specific to your situation.

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.