Question

Okay, so in my page I have a list of links:

@foreach (var item in Model)
{
    @Html.ActionLink(item.Name, "Recruitments", new { Id = item.Id })
    <br />
}

And what I want is for the partialview to return somewhere else on the page, in a placeholder I've set aside.

Is this possible? Or do I have to use jquery ajax calls instead somewhere?

Was it helpful?

Solution

you can @Ajax.ActionLink in asp.net mvc, it has different overloads you can use according to your requirements here is the code:

@Ajax.ActionLink("ActionName", // action name
                "Recruitments", //controller name
                 new { Id = item.Id }, // route values
                 new AjaxOptions { HttpMethod = "GET", //HttpMethod Get or Post
                 InsertionMode = InsertionMode.Replace,  // Replace content of container
                 UpdateTargetId = "Container", // id of element in which partial view will load 
                 OnComplete = "Completed();" }) // js function to be executed when ajax call complete


<div id="Container">
</div>

<script>

function Completed()
{
alert("completed");
}
</script>

OTHER TIPS

I did had a problem with partial for your problem post some code so I understand your problem.

Either you should use a razor helper, either you simply use jquery to manipulate the dom.

note that jquery is pretty simple

$("#selectorOnYourPlaceHolder").html($("#selectorOnYourLinks").html());
$("#selectorOnYourLinks").html("")

You want to do this with Ajax:

$.ajax({
        type: "GET", url: "somePageOrHandler.aspx", data: "var1=4343&var2=hello",
        success: function(data)
            {
                $('#someDivInPlaceHolder').html( data);
            }
         });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top