2016-10-07 15 views
0

これは私のLINQのコードです:表示同じデータを

public JsonResult getfull() 
    { 
     var coursename = Session["course"].ToString(); 
     var location = Session["location"].ToString(); 
     var result = (from insti in db.Institute_Master 
         join course in db.Course_Detail on insti.InstituteId equals course.InstituteId 
         join coursemaster in db.Course_Master on course.CourseId equals coursemaster.CourseId 
         join facility in db.Facility_Detail on insti.InstituteId equals facility.InstituteId 
         join masterfacility in db.Facility_Master on facility.FacilityMasterID equals masterfacility.FacilityMasterId 
         where coursemaster.CourseName == coursename || insti.City == location 
         select new 
         { 
          //Id = insti.InstituteId, 
          name = insti.InstituteName, 
          university = insti.University, 
          Contact = insti.ContactNo, 
          address = insti.Address, 
          email = insti.EmailId, 
          zipcode = insti.Zipcode, 
          country = insti.Country, 
          state = insti.State, 
          city = insti.City, 
          start = insti.EstablishOn, 
          image = insti.ProfilePhoto, 
          fees = course.TotalFees, 
          mode = course.Mode, 
          coursename = coursemaster.CourseName, 
          duaration = coursemaster.duration, 
          discription = coursemaster.Discription, 
          eligibility = coursemaster.Eligibility, 
          recognization = coursemaster.Recognization, 
          facility = masterfacility.FacilityName 


         }).Distinct(); 

     ViewBag.facilies = list; 

     return Json(result, JsonRequestBehavior.AllowGet); 
    } 

この方法は、角JSで扱うと、私は以下のangularjsコードを言及しているリターンJSONの結果です。

私はAngularJsを使用しています。データを表示するために、特定の施設でレコードが繰り返されています。

これは私のテーブルです:

enter image description here

これは彼の施設のために再度同じレコードを表示する問題である: enter image description here

これは私のAngularjsコード

<h1>Show Institute</h1> 
<div data-ng-app="myModule"> 
    <div data-ng-controller="myController"> 
<ul class="w3-ul w3-card-4" data-ng-repeat="detail in employees"> 
<li class="w3-padding-16 institute-list"> 
    <span class="w3-xlarge">{{detail.name | uppercase}}</span>,<span>{{detail.address}}</span><br> 
    <img alt="image" src="~/images/{{detail.image}}" class="w3-left w3-margin-right img-institute-list" style="width:60px" /> 
    <span class="w3-xlarge">{{detail.coursename | uppercase}}</span>,<span>Course Duration {{detail.duaration}}</span>,<span>Course Mode {{detail.mode}}</span>,<span>{{detail.discription}}</span><br> 
    <span><b>Fees : </b>INR {{detail.fees}}</span><br> 
    <span><b>{{detail.recognization | uppercase}}</b> Recognised</span><br> 


    <span>Facility {{detail.facility}}</span> 
    <button class="w3-btn w3-blue" id="detail">More Details</button> 


    </li> 

     <script> 
      $(document).ready(function() { 
       $("button").click(function() { 
        $("#moredetail").toggle(); 
       }); 
      }); 
    </script> 

    <li class="w3-padding-16 institute-list" id="moredetail" style="display:none"> 
     <span class="w3-xlarge">{{detail.contact}}</span> <span class="w3-xlarge">{{detail.email}}</span><br /> 
     <span class="w3-xlarge" >{{detail.zipcode}}</span> <span class="w3-xlarge" >{{detail.country}}</span> <br/> 
     <span class="w3-xlarge" >{{detail.state}}</span> <span class="w3-xlarge" >{{detail.city}}</span>  <br /> 
      <span class="w3-xlarge" >{{detail.start}}</span>, 
    </li> 
</ul> 

    </div> 
    </div> 
    <script> 
     var app = angular 
     .module("myModule", []) 
     .controller("myController", function ($scope, $http) { 

      $http.get("/home/getfull") 
       .then(function (response) { 
        $scope.employees = response.data; 
       }); 
     }) 
</script> 

    </div> 
</body> 
</html> 

これですコードはビュービューでデータを表示するためのものですjsonメソッド Ca誰もこれで私を助けますか?

答えて

0

「新規選択」があるので、同じレコードが追加され続けます。あなたは必要なもののようなモデルである:

public class CourseModel 
{ 
          public int InstituteId {get; set;} 
         public string InstituteName {get; set;} 
          public string University {get; set;} 
          ETC... 
} 

次に、あなたのMVCコントローラで:

var result = (from insti in db.Institute_Master 
          join course in db.Course_Detail on insti.InstituteId equals course.InstituteId 
          join coursemaster in db.Course_Master on course.CourseId equals coursemaster.CourseId 
          join facility in db.Facility_Detail on insti.InstituteId equals facility.InstituteId 
          join masterfacility in db.Facility_Master on facility.FacilityMasterID equals masterfacility.FacilityMasterId 
          where coursemaster.CourseName == coursename || insti.City == location 

var courses = new List<CourseModel>(); 
foreach(var c in result) 
{ 
courses.Add(new CourseModel 
{ 
         InstitueName = insti.InstituteName, 
         University = insti.University, 
         ETC... 
}); 
} 

return Json(courses, JsonRequestBehavior.AllowGet; 
} 

私はこれが役に立てば幸い!

+0

ありがとうございましたが、あなたが書いたコードにエラーがあります。 –

関連する問題