Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load partial view in a div MVC

Tags:

I have a button on my MVC view on click of it, it should add a partial view in a 'div', by calling an action which takes an object as a parameter

I tried out some thing like this:

$('#buttonId').onclick(function(){

$('#divid').load(@Html.Action("ActionName","ControllerName",new{parameterName = objectToPass}))

});

but it loads the actionresult/partial view on page load itself not a click of button

Any Idea?

like image 999
BreakHead Avatar asked Mar 20 '12 14:03

BreakHead


1 Answers

Try to use

@Url.Action

instead of

@Html.Action

Or you can use ajax, for example:

$('#buttonId').click( function() {
    $.ajax({
        type: 'POST',
        url: '@Url.Content("~/ControllerName/ActionName")',
        data: objectToPass,
        success: function (data) {
           $('#divid').innerHTML = data;
        }
    });
}
like image 199
Save Avatar answered Sep 23 '22 03:09

Save