1

I have a table named Courses,CoursePreRequisites and a third tale named PreRequisiteTracking.One particular Course can contain multiple PreRequisites and so I couldn't pass a foreign key in the Courses tables and instead created the PreRequisiteTracking table.

Eg:A Course,say, Introduction to Java.This may have the following prerequsites:OOPS,Basic Programming Knowledge. These prerequisites are given in checkboxes while creating a new course. Now my problem is how do I join all these tables and list them in a View. I joined all theses tables but since only Ids are being passed I am not able to retrieve the PreRequisites to show in the View.

Kindly help me,Thanks in advance

1 Answer 1

0

I got the answer to my post.

What I did was in my Class I declared a property as :

enter code here
`public class CourseModel{`
`public string coursename{set;get;}`
`public string coursecode{set;get;}`
`public string Benefits{set;get;}`
`public IEnumerable<CoursePreRequisites> display{set;get;}`
       }

Here CoursePreRequisites is of table whose value i wish to display in the view.

Then in my controller in the Details action I gave:

enter code here:var query=(from cours in db.courses
       join level in db.courselevels on cours.levelid equals level.levelid
       where cours.courseid==id
       select new CourseModel
       {
          coursename=cours.CourseName,
          coursecode=cours.CourseCode,
          Benefits=cours.Benefits,
          display=(from courss in db.course
                   join track in db.prerequisitetrack on courss.CourseId equals                                            track.CourseId
                    join prerequistes in db.courseprerequisite on prerequistes.prerequsiteId equals track.prerequsiteId
                    where track.courseid==id select prerequsite).AsEnumerable()
        }).First() as Models.CourseModel;

Then create a strongly-typed view of Class type and give :

enter code here:<%foreach(var item in Model.display) {%>  
   <%:item.PreRequisites %>

Hope this will be useful to others.I tried and it worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.