这是我的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);
}
这个方法是返回json结果,由angular js处理,我在下面提到angularjs代码。
我正在使用AngularJs显示数据,我的记录正在重复进行特定设施。
这是我的表格:
这是我的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方法中显示数据 任何人都可以帮助我吗?
答案 0 :(得分: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;
}
我希望这有帮助!