简体   繁体   中英

Durandal and partial views

I`have ASP.NET Durandal Application.

I need to make one partial view which would be used many times, I`ve made tried this :

define(function () {
    return {
        comments: [],
            $.ajax({                
                url: '#/comments/index/' + id,
                success: function(data) {
                    that.comments = data;
                }
            });
        }
    };
});

This code is inside another viwemodel which calls /ViewModels/Comments/Index and passes parameter, but this Comments/Index returns full HTML(With layout).

this is comments route configugration

{ route: 'comments/index/:id', moduleId: 'viewmodels/comments/index', nav: false}

How i can get comments html without layout? And is this good approach for partial views?

经过大量搜索,这解决了我的问题

<div data-bind=" compose: { model: 'viewmodels/Posts/_index', activate: true, activationData: [2, 100] }"></div>

You need to return partial view instead of the view , it will pass the view without the layout. Try using,

return PartialView(); instead of return View()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM