jquery load with asp.net MVC partial view

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 22:26:44

问题


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

Here is how I am coding the 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.


回答1:


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

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



回答2:


Try letting the framework create the URL. Use the

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


来源:https://stackoverflow.com/questions/5210548/jquery-load-with-asp-net-mvc-partial-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!