[英]Calling function from BLL layer to controller in MVC5
public class StudentBLL {公共 class StudentBLL {
StudentDAL objStudent = new StudentDAL();
public List<StudentDAL> GetAllStudnets() {
List<StudentDAL > lstStudents = objStudent.GetStudentList().Tables[0].AsEnumerable().Select(
dataRow => new StudentDAL
{
StuID = dataRow.Field<int>("StudentId"),
StuName = dataRow.Field<int>("StudentName")
}).ToList();
return lstStudents;
}
}
I want to call this function in my Home Controller:我想在我家 Controller 中调用这个 function:
public JsonResult LoadStudents(int randomJunk)
{
//call function here ??
List<SelectListItem> selectListItems = new List<SelectListItem>();
//selectListItems.Add(si);
// selectListItems.Add(si1);
var notesTypes = new SelectList(selectListItems, "Value", "Text");
return Json(notesTypes, JsonRequestBehavior.AllowGet);
}
So how can call the return list to my Home Controller, I'm really confused and I'm not a student那怎么能叫退货单到我家Controller,我真的很迷茫我又不是学生
Create an object of class StudentBLL and call the method GetAllStudnets
with this object创建 class StudentBLL 的 object 并使用此 object 调用方法GetAllStudnets
StudentBLL obj = new StudentBLL ();
List<StudentDAL> ls = obj.GetAllStudnets();
Best practise is to create an interface with the required methods.最佳实践是使用所需方法创建接口。 create a class which implements the method.创建一个实现该方法的 class 。 Use dependency injection to inject the class in the controller to call the method.使用依赖注入将controller中的class注入调用该方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.