jQuery jquery加载asp.net MVC部分视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5210548/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jquery load with asp.net MVC partial view
提问by DotnetSparrow
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 加载方法。
回答by Darin Dimitrov
Your controller action requires a DateTime parameter that you need to supply when invoking the AJAX request:
您的控制器操作需要一个 DateTime 参数,您需要在调用 AJAX 请求时提供该参数:
$(function() {
$('#dvGames').load(
'<%= Url.Action("Partial3", "LiveGame") %>',
{ gameDate: '2011-03-06' }
);
});
回答by rcravens
Try letting the framework create the URL. Use the
尝试让框架创建 URL。使用
<%= Url.Action("LiveGame","Partial3") %>