user1493249
user1493249

Reputation: 11

auto refresh of div in mvc3 ASP.Net not working

ViewData.cshtml(Partial View) This is partial View

<table id="users" class="ui-widget ui-widget-content" width="100%" align="center">
    <thead>
        <tr class="ui-widget-header ">
            <th width="30%" align="center">Date</th>
            <th width="30%" align="center">Bill Amount</th>
            <th width="30%" align="center">PayNow</th>

        </tr>
    </thead>
    <tbody>
        @{
            for (int i = @Model.bill.Count - 1; i >= 0; i--)
            {
            <tr>
                <td width="30%" align="center">@Model.billdate[i]</td>
                <td width="30%" align="center">@Model.bill[i]</td>
                <td width="30%" align="center">                    
                    <a class="isDone" href="#" data-tododb-itemid="@Model.bill[i]">Paynow</a>
                </td>
            </tr>
            }
        }
    </tbody>
</table>

Index.cshtml(View) This is my view

<script type="text/javascript">
$(document).ready(function () {
    window.setInterval(function () {
        var url = '@Url.Action("ShowScreen", "Home")';
        $('#dynamictabs').load(url)
    }, 9000);
    $.ajaxSetup({ cache: false });
});
</script>
<div class="dynamictabs">
    @Html.Partial("ShowScreen")
</div>

HomeController.cs(Controller) This is home controller

public ActionResult Index()
{
   fieldProcessor fp= new fieldProcessor();
   return View(fp);
}

public ActionResult ShowScreen()
    {
        return View();
    }

fieldProcessor.cs My Model

public class fieldProcessor 
{
    public List<int> bill { get; set; }
    public List<string> billdate { get; set; }
}

Still Div is not getting refreshed.

Upvotes: 1

Views: 1063

Answers (2)

Pablo Claus
Pablo Claus

Reputation: 5920

It will work with some code changes:

1) like greg84 said:

This line:

$('#dynamictabs').load(url)

Should be:

$('.dynamictabs').load(url)

2) Your controller should be like this:

  public ActionResult ShowScreen()
    {
        fieldProcessor fp = new fieldProcessor();
        /*Load fieldProcessor object*/

        return View(fp);
    }
  public ActionResult Index()
    {
        fieldProcessor fp = new fieldProcessor();
        /*Load fieldProcessor object*/
        return View(fp);
    }

3) ShowScreen and Index should be strong typed views:

@model YourApp.Models.fieldProcessor

4) When your code call the partial view, you should pass the model, like this:

<div class="dynamictabs">
    @Html.Partial("ShowScreen",Model)
</div>

Upvotes: 0

greg84
greg84

Reputation: 7609

This line:

$('#dynamictabs').load(url)

Should be:

$('.dynamictabs').load(url)

...because your div has a class of dynamictabs, not an id.

Upvotes: 1

Related Questions