Reputation: 15579
This is for a recruitment website: I have a form which displays the job and there is an Apply button. If user click on Apply a pop-up will open, where user clicks his info and clicks on Send button:
When user clicks on Apply a modal will open... this modal contains user information, i.e. name and his CV (we keep a copy of use CV in DB from prev job applications):
Now, I want to make this an efficient design... I don't want to load user CV into the View to begin with, to improve the load time... so I am thinking of putting the whole Modal in a ChildAction
as below:
DisplayJob.cshtml
@model JobViewModel
@Html.DisplayFor(m => m.JobDescription);
<input type="button" value="Apply" />
@Html.Action("ApplyForJobModal", new { /* route params */ }); // modal to apply for job
Controller Actions:
public class JobController : Controller
{
public ActionResult DisplayJob()
{
var jobViewModel = <-- Get JobViewModel from DB
return View(jobViewModel);
}
[ChildActionOnly]
public ActionResult ApplyForJobModal(/* route params */)
{
var userInfoViewModel = <-- Get user name from Claims and CV from DB
return PartialView("_ApplyForJobModal", userInfoViewModel);
}
}
I am trying to understand how the ChildAction
PartialView is loaded:
ChildAction
? Or everything is sent back in one single request?Upvotes: 0
Views: 88
Reputation: 15579
I inspected the code using Chrome Network tab:
Call to View
and PartialView
(Action
and ChildAction
) are part of the same HttpRequest, which means displaying of the view is delayed until ChildAction
is ready and then the entire result it sent to the client as part of one single response.
Another point to mention is that the Constructor
of JobController
was called 2 times, which means both Action
and ChildAction
instantiated its own instance of JobController
.
Upvotes: 0