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:
- Does the client sends 2 requests to the server, one for loading the view and another for loading the
ChildAction
? Or everything is sent back in one single request? - If 2 requests are sent to the server, is the display of the main view delayed until the child is loaded?
- If the view is delayed until child action is loaded, would it be more efficient to load the modal using ajax, which lets the page to display and load the modal behind the scene?
I inspected the code using Chrome Network tab:
Call to
View
andPartialView
(Action
andChildAction
) are part of the same HttpRequest, which means displaying of the view is delayed untilChildAction
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
ofJobController
was called 2 times, which means bothAction
andChildAction
instantiated its own instance ofJobController
.