用asp.net MVC局部视图加载jquery

时间:2022-11-30 18:06:05

I have a partial view and I want to render it in main view using jquery.

我有一个局部视图,我想使用jquery在主视图中呈现它。

Here is how I am coding the jQuery:

以下是我编写jQuery的方法:

$(document).ready(function() {
        $("#dvGames").load("/LiveGame/Partial3");
});

where as controller method looks like this:

控制器方法如下所示:

public ActionResult Partial3(DateTime gameDate)
{
    return View("Partial3");
}

I dont see anything. I tried

我没有看到任何东西。我试过了

<% Html.RenderPartial("Partial3"); %> 

and it works but I want to filter data in partial view so I am using jquery load method.

它工作但我想在局部视图中过滤数据,所以我使用jquery加载方法。

2 个解决方案

#1


15  

Your controller action requires a DateTime parameter that you need to supply when invoking the AJAX request:

您的控制器操作需要在调用AJAX请求时需要提供的DateTime参数:

$(function() {
    $('#dvGames').load(
        '<%= Url.Action("Partial3", "LiveGame") %>', 
        { gameDate: '2011-03-06' }
    );
});

#2


0  

Try letting the framework create the URL. Use the

尝试让框架创建URL。使用

<%= Url.Action("LiveGame","Partial3") %>

#1


15  

Your controller action requires a DateTime parameter that you need to supply when invoking the AJAX request:

您的控制器操作需要在调用AJAX请求时需要提供的DateTime参数:

$(function() {
    $('#dvGames').load(
        '<%= Url.Action("Partial3", "LiveGame") %>', 
        { gameDate: '2011-03-06' }
    );
});

#2


0  

Try letting the framework create the URL. Use the

尝试让框架创建URL。使用

<%= Url.Action("LiveGame","Partial3") %>