HW90
HW90

Reputation: 1983

Render partial view dynamically

I've one more question. I have a view which is containing an "add" link. Everytime I press this link a partial view should be added dynamically (for example with jQuery).

I've tried to do that by this way:

 $('#Div1').load('<%= Url.Action( "Video", "ddd", new { id = "1", url="ko" } ) %>');

But this method do not add a partial it just replace the content of "Div1" with the partial.

When I try:

$('#Div1').append('<%= Url.Action( "Video", "ddd", new { id = "1", url="ko" } ) %>');

there is something added to my Div but no partial view. Just the path of the partial view is added: /de/Market/ddd/Video/1?url=ko

My code in the controller looks like this:

public ActionResult Video(string url, int id)
        {
            ViewModels.Video v = new Video();
            v.URL = url;
            v.ID_Video = id;
            return PartialView("Video", v);

        }

Any ideas how to solve this problem? (I'm using MVC2)

Upvotes: 2

Views: 5017

Answers (2)

Aliostad
Aliostad

Reputation: 81660

Use

$('#Div1').append(...)

This should help.

Upvotes: 0

DarthJDG
DarthJDG

Reputation: 16591

You can add your dynamically loaded content wrapped in individual divs to #Div1 as a container:

$('<div>').appendTo('#Div1').load('<%= Url.Action( "Video", "ddd", new { id = "1", url="ko" } ) %>');

Upvotes: 5

Related Questions