Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7928889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:53:08+00:00 2026-06-03T19:53:08+00:00

I have the following: public Class Vacancy{ public int VacancyID {get;set;} public List<Application> Applications

  • 0

I have the following:

public Class Vacancy{
   public int VacancyID {get;set;}
   public List<Application> Applications {get;set;}
}
public Class Applicant{
   public int ApllicantID {get;set;}
   public List<Application> Applications {get;set;}
}
public Class Application{
   public int ApplicationID {get;set;}
   public int VacancyID {get;set;}
   public int ApplicantID {get;set;}
   public virtual Applicant Applicant {get;set;}
   public virtual Vacancy Vacancy {get;set;}
 }

then i created a control on Vacancy Model.
what i want to do:
1) view all vacancies
2) when a vacancy selected i wanna show its list of application in the same page
3) when an application is selected from the previous step i wanna get the applicant details
i tried to use this tutorial
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/reading-related-data-with-the-entity-framework-in-an-asp-net-mvc-application
but i’m going no where with it, i hit a wall and i’m so confused atm

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:53:11+00:00Added an answer on June 3, 2026 at 7:53 pm

    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.

    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).

    Assuming you have a DBContext class like this

    public class YourDBContext:DbContext
    {
        public DbSet<EFCodeFirst.Models.Vacancy> Vacancies { set; get; }
        public DbSet<EFCodeFirst.Models.Applicant> Applicants { set; get; }
        public DbSet<EFCodeFirst.Models.Application> Applications { set; get; }
    }
    

    To List All Vacancies, Create an Action called “Index”

    public ActionResult Index()
    {
       YourDBContext db = new YourDBContext();
       var allVacancies = db.Vacancies.ToList();
       return View(allVacancies);
    }
    

    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

    @model IEnumerable<EFCodeFirst.Models.Vacancy>
    
    <h2> All Vacancies </h2>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <div id="divVacancies">
    @foreach (var vacancy in Model)
    {
      <p> @Html.ActionLink(vacancy.VacancyID.ToString(), "GetApplications","Job", new { @id = vacancy.VacancyID }, new {  @class = "ajaxLink" })</p>
    }
    </div>
    
    <div id="divApplications"></div>
    
    <script type="text/javascript">
        $(function () {
            $(".ajaxLink").click(function (e) {
                e.preventDefault();
                var target = $(this).attr("href");
                $("#divApplications").load(target);
            });
         });
    </script>
    

    In this view we included a reference for jQuery 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 asynchronous request to another action called GetApplications 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.

    Go back to Job controller and create an Action method called GetApplications like this.

        public ActionResult GetApplications(int id)
        {
            SampleContext db = new SampleContext();
            var allApplications = db.Applications.Where(x => x.VacancyID == id).ToList();
            return View(allApplications);
        }
    

    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 GetApplications.cshtml with the below content.

    @model IEnumerable<EFCodeFirst.Models.Application>
    <h2>Applications </h2>
    @foreach (var application in Model)
    {
     <p> @Html.ActionLink(application.ApplicantID.ToString(), "GetApplicants", new { @id = application.VacancyID, @class = "ajaxLink" })</p>
    }
    

    Straight forward ! Simply printing the result in a loop.

    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.

    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

    Note : Use Firebug /fiddler to see what (ajax) requests are going to the action methods with what parameter. This will help you to understand how it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have following classes public class MyPropertyBase { public int StartOffset { get; set;
I have the following: public class Foo { public int x { get; set;
Say i have the following: public class Person{ public int ID {get; set;} public
I have following type public class TransactionDetails { public int TransID {get; set;} public
I have following entities: public class Product { [Key] public int Id{get;set;} //other properties
I have the following: public class Address { public string Email { get; set;
Suppose I have the following: public class MyObject { public string Name {get; set;}
I have the following class public class UIControl { public string FName{ get; set;
I have the following class: public class Account { public int AccountID { get;
I have following code public interface IEntity { int Id { get; set; }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.