Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am pretty sure that you don't want anyone here to code it from A-Z. So here i am giving you some starting. The half part of the solution i am providing and leaving you to do the rest yourself.</p> <p>First of All you have some Spelling issues in your code. Class keyword should be lowercase. And you should use the same IDs for creating the foreign key reference. (If you have ApplicantId in your Application Class as your Primary Key, you should use the same spelling in your Applications class. Entity framework code-first creates the foreign key relation when it sees the same name like that).</p> <p>Assuming you have a <code>DBContext</code> class like this</p> <pre><code>public class YourDBContext:DbContext { public DbSet&lt;EFCodeFirst.Models.Vacancy&gt; Vacancies { set; get; } public DbSet&lt;EFCodeFirst.Models.Applicant&gt; Applicants { set; get; } public DbSet&lt;EFCodeFirst.Models.Application&gt; Applications { set; get; } } </code></pre> <p>To List All Vacancies, Create an Action called "Index"</p> <pre><code>public ActionResult Index() { YourDBContext db = new YourDBContext(); var allVacancies = db.Vacancies.ToList(); return View(allVacancies); } </code></pre> <p>So we should have a View for this action where we need to display all the Vacancies. So add an Index View which is strongly typed to a collection of Vacancy Model like this</p> <pre><code>@model IEnumerable&lt;EFCodeFirst.Models.Vacancy&gt; &lt;h2&gt; All Vacancies &lt;/h2&gt; &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"&gt;&lt;/script&gt; &lt;div id="divVacancies"&gt; @foreach (var vacancy in Model) { &lt;p&gt; @Html.ActionLink(vacancy.VacancyID.ToString(), "GetApplications","Job", new { @id = vacancy.VacancyID }, new { @class = "ajaxLink" })&lt;/p&gt; } &lt;/div&gt; &lt;div id="divApplications"&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; $(function () { $(".ajaxLink").click(function (e) { e.preventDefault(); var target = $(this).attr("href"); $("#divApplications").load(target); }); }); &lt;/script&gt; </code></pre> <p>In this view we included a reference for <code>jQuery</code> library which we will be using to make some ajax calls. We need to to use ajax show the Application information for a selected vacancy in the same page. for this we will make an <code>asynchronous</code> request to another action called <code>GetApplications</code> inside our Job controller with the vacancy id as the parameter. We are simply looping thru all available Vacancies and creating an Anchor tag for that here.</p> <p>Go back to Job controller and create an Action method called <code>GetApplications</code> like this.</p> <pre><code> public ActionResult GetApplications(int id) { SampleContext db = new SampleContext(); var allApplications = db.Applications.Where(x =&gt; x.VacancyID == id).ToList(); return View(allApplications); } </code></pre> <p>That is pretty clear to understand , We are querying to get all applications for the selected Vacancy, Return that to a View. So we need to create a view called <code>GetApplications.cshtml</code> with the below content.</p> <pre><code>@model IEnumerable&lt;EFCodeFirst.Models.Application&gt; &lt;h2&gt;Applications &lt;/h2&gt; @foreach (var application in Model) { &lt;p&gt; @Html.ActionLink(application.ApplicantID.ToString(), "GetApplicants", new { @id = application.VacancyID, @class = "ajaxLink" })&lt;/p&gt; } </code></pre> <p>Straight forward ! Simply printing the result in a loop.</p> <p>That is it. It should work. Whenever you click on the vacancy link, it will make a call to the GetApplications method with the id as parameter and that action method will return a view with HTML markup which listss all applications for that vacancy id. </p> <p><strong>Once you do this, you should be able to create the second part yourself. It is the same logic. You may need to create a similar GetApplicants action method which returns data. Good Luck</strong></p> <p><strong>Note</strong> : Use <code>Firebug</code> /<code>fiddler</code> to see what (ajax) requests are going to the action methods with what parameter. This will help you to understand how it works.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload