Ajax.BeginForm refreshing the whole page in MVC

后端 未结 2 462
余生分开走
余生分开走 2021-01-24 17:26

I\'ve been trying to add some Ajax functionality to my mvc site, however, I run into a problem regarding page refreshing. I\'ve created an rss view on my homepage sidebar, which

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-24 17:43

    I use an ajax call in jquery for this

    $('#SelectedFeedOption').change(function() {
        $.ajax({
            url: "@(Url.Action("Action", "Controller"))",
            type: "POST",
            cache: false,
            async: true,
            data: { data: $('#SelectedFeedOption').val() },
            success: function (result) {
                $(".feedList").html(result);
            }
       });
    });
    

    Then put the contents of your feedList div in a partial view and on your controller

    public PartialViewResult FeedList(string data){
        Model model = (get search result);
        return PartialView("_feedList", model);
    }
    

    Hopefully this helps.

提交回复
热议问题