Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
hi this is my action :
C#
public ActionResult Index(int page=1)
       {
           var model = (from item in _db.News
                        join c in _db.SPNews on item.Id equals c.NewsId
                        orderby item.CreateDate
                        where c.GroupNewsId == 1
                        select item).ToPagedList(page, 6);
           if(Request.IsAjaxRequest())
           {
               return PartialView("_AllNewsView", model);
           }
           return View(model);
       }


this is view :
HTML
@model IPagedList<News>
@{
    ViewBag.Title = "خبرها";
}

<h2>آرشیو کامل خبرها</h2>
@Html.Partial("_AllNewsView", Model)


this is partial view :
HTML
@model IPagedList<News>
<div id="ViewAllNews">
    <div id="portfolio">
        <ul>
            @{int count = 0;}
            @foreach (var item in Model)
            {
                if (count % 2 == 0)
                {
                    <li>

                        <img src="@Url.Content(item.ImageUrl)" alt="" />
                        <h2> @item.Title </h2>
                        <p>@item.Summary</p>
                        <p class="readmore"><a href="#">Read More Here »</a></p>
                    </li>
                }
                else
                {
                    <li class="last">
                        <img src="@Url.Content(item.ImageUrl)" alt="" />
                        <h2>@item.Title</h2>
                        <p>@item.Summary</p>
                        <p class="readmore"><a href="#">Read More Here »</a></p>
                    </li>
                }
                count++;
            }

        </ul>
    </div>
    <div class="Pagelist" data-otf-target="#ViewAllNews">
        @Html.PagedListPager(Model, page => Url.Action("index", new { page }),
        PagedList.Mvc.PagedListRenderOptions.ClassicPlusFirstAndLast)
    </div>

</div>


this my code in otf js:
HTML
$(function () {

    var getpage = function () {

        var $a = $(this);

        var options = {
            url: $a.attr("href"),
            type: "GET"
        };
        $.ajax(options).done(function (data) {
            var target = $a.parents("div").parents("div").attr("data-otf-target");
            $(target).replaceWith(data);
           
        });
        return false;
    };
    $(".pagination a").click(getpage);
});


this is Bundleconfig:
C#
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                      "~/Scripts/jquery-{version}.js",
                      "~/Scripts/jquery-slider.js",
                      "~/Scripts/jquery-custom.js",
                      "~/Scripts/jquery-tabs.js",
                      "~/Scripts/jquery-prettyPhoto.js",
                      "~/Scripts/jquery.unobtrusive*",
                      "~/Scripts/otf.js"
                     ));


but $.ajax(options) not work when i click on tag in my page
Posted
Comments
[no name] 6-Nov-14 13:22pm    
you have bundled all the scripts but have you rendered them in the layout or the specific view page?
Please check the developer tool for the console errors that would exactly specify the problem

1 solution

I m nt sure what this means :-
JavaScript
var $a = $(this);

Do the variable name should contain '$' in it ?


Here is an example of the ajax request to make through jQuery :-
JavaScript
$.ajax({
        type: "POST",
        url: "../WebMethods/WebService.asmx/GetData",
        data: "{Id:'" + Id + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function (response) {
            var result = JSON.parse(response.d);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            ShowError(failMessage, 450, 100);
        }
    });


Hope this will be helpful for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900