public ActionResult CCEEvaluationBlukUpload(int BranchID, int ClassID, int BranchSectionID)
{
ViewBag.Subjects = BindSubjects(BranchID, ClassID, BranchSectionID);
}
public TempDataDictionary BindSubjects(int BranchID, int ClassID, int BranchSectionID)
{
var data = db.GetAcademicStaffSubjectDetailsByClassTeacher((int?)dts.PersonalID, BranchID, dts.AcademicYearID, ClassID).ToList();
TempData["result"] = data;
return TempData["result"];
}
嗨朋友们,在上面的代码我调用了一个带参数的BindSubjects方法。在bind方法中,它将执行结果并将数据存储在tempdata中并返回tempdata,但我不知道如何在执行该方法后返回临时数据。请帮我如何将结果返回到viewbag。
答案 0 :(得分:0)
最好使用对象或动态类型而不是temData [“result”]
答案 1 :(得分:0)
好吧,如果您想将结果作为ViewBag
返回,为什么要首先分配给TempData
。你可以这样做:
ViewBag.Subjects = db.GetAcademicStaffSubjectDetailsByClassTeacher((int?)dts.PersonalID, BranchID, dts.AcademicYearID, ClassID).ToList();
或者这个:
TempData["result"] = db.GetAcademicStaffSubjectDetailsByClassTeacher((int?)dts.PersonalID, BranchID, dts.AcademicYearID, ClassID).ToList();
在您的CCEEvaluationBlukUpload
控制器中。
在您的视图中,您可以将结果检查为:
@if(ViewBag.Subjects != null)
{
//code goes here
}
或者这个:
@if(TempData["result"] != null)
{
//code goes here
}
答案 2 :(得分:0)
如果您不想浪费内存,还有另一种选择。
public ActionResult CCEEvaluationBlukUpload(int BranchID, int ClassID, int BranchSectionID)
{
var subjects = BindSubjects(BranchID, ClassID, BranchSectionID);
}
private List<GetAcademicStaffSubjectDetailsByClassTeacher> BindSubjects(int BranchID, int ClassID, int BranchSectionID)
{
return db.GetAcademicStaffSubjectDetailsByClassTeacher((int?)dts.PersonalID, BranchID, dts.AcademicYearID, ClassID).ToList();
}
如果您真的想使用TempData,请添加一行:
public ActionResult CCEEvaluationBlukUpload(int BranchID, int ClassID, int BranchSectionID)
{
var subjects = BindSubjects(BranchID, ClassID, BranchSectionID);
TempData["result"] = subjects;
}