William
William

Reputation: 330

How to render a partial view generated by a controller in a main view?

This is my link to a partial view:

@Ajax.ActionLink("All", "All", "Products", new { id = Model.id_product }, new AjaxOptions()
       {
           HttpMethod = "GET",
           UpdateTargetId = "divImages",
           InsertionMode = InsertionMode.Replace
       })
                <div id="divImages"></div>

and here's the method being invoked and returns the partial view:

public PartialViewResult All(int id)
        {
            List<Image> model = db.Images.Where(x => x.id_product == id).ToList(); 
            return PartialView("_File", model); 
        }

I want my partial view to be loaded immediately after the main view loaded instead of the link to the partial view. How can I do that?

Upvotes: 0

Views: 286

Answers (1)

user3559349
user3559349

Reputation:

To render a partial view generated by a controller method in the main view, use @Html.Action() or @{ Html.RenderAction(); }

@{ Html.RenderAction("All", "Products", new { id = Model.id_product }); }

Upvotes: 1

Related Questions