1

ViewData.cshtml(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) 这是我的看法

<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) 这是家庭控制器

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

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

fieldProcessor.cs 我的模型

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

仍然 Div 没有得到刷新。

4

2 回答 2

1

这一行:

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

应该:

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

...因为您的 div 有一动态标签,而不是 id。

于 2012-06-30T23:12:34.713 回答
0

它将适用于一些代码更改:

1) 就像 greg84 说的:

这一行:

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

应该:

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

2)你的控制器应该是这样的:

  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 和 Index 应该是强类型视图:

@model YourApp.Models.fieldProcessor

4)当您的代码调用局部视图时,您应该传递模型,如下所示:

<div class="dynamictabs">
    @Html.Partial("ShowScreen",Model)
</div>
于 2012-06-30T23:43:57.743 回答