开发者

MVC and jQuery template?

I have a controller that returns a custom model back to its view. Within this model is a collection of products and prices which are rendered in the view, alongside other information that is required by the page.

However, I'd like to use jQuery templates to allow an AJAX update of those products and prices.

I guess its开发者_开发问答 not possible to render the template with initial values so how do I return a model that includes both "static" information (ie wont chnage on the page) and also information that I do want to include in the template as it will change dependent on input of the user?


You can load content via jquery from your control like this:

Jquery:

function lastPostFunc(movies) {

            $.each(movies, function(i) {

                var milli = this.ReleaseDate.replace(/\/Date\((-?\d+)\)\//, '$1');
                var d = new Date(parseInt(milli));

                $("#Movie_list").append("<tr class=wrdLatest id=" + this.Id + "><td>" + this.Id + "</td><td>" + this.Title + "</td><td>" + d + "</td><td>"
         + this.Genre + "</td><td>" + this.Price + "</td><td>" + this.Rating + "</td></tr>");
            });

        }
        $(window).scroll(function() {
            if ($(window).scrollTop() + 100 > $(document).height() - $(window).height()) {

                var name = id; //$(".wrdLatest:last").attr("id");
                var value = { skip: name };
                $.post("/Movies/GetMovies/", value, lastPostFunc, "json");
                id += 50;
            }
        }); 

Controller

[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult GetMovies(string skip)
        {
            // caching the categories 

            int idtoSkip = Convert.ToInt32(skip);
            var movies = from m in _db.Movie
                         where m.Id > idtoSkip & m.Id < idtoSkip + 50
                         select m;
            return Json(movies);
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜