如何使用ViewBag显示数据

How use ViewBag to display data

学校控​​制器

schoolBLL content = new schoolBLL ();
DatabaseSchool  dbSchool = content.GetSchoolInfoById(LoginStaffId);

if (dbschool != null)
{ 
    string textcontent = dbschool .text_content;
}

class 文件

public DatabaseSchool GetSchoolInfoById(int StaffId)
{
    return SchoolRepo.Find(a => a.schoolcontent_id == StaffId).FirstOrDefault();
}

因此,我正在尝试将数据显示到带有此标签的 HTML 页面中

如何将值从控制器传递到 HTML 页面?

我已经尝试使用 ViewBag 但它不起作用!

要将数据显示到 html 页面,请尝试以下操作:

学校负责人:

schoolBLL content = new schoolBL();

DatabaseSchool dbSchool = content.GetSchoolInfoById(LoginStaffId);
    
if(dbschool != null)
{ 
   TempData["textcontent"] = dbschool.text_content;
}

HTML:

   <textarea id="txtcontent" class="form-control" rows="20">@TempData["textcontent"]</textarea>

最好用CSHTML:

@{
    Layout = null;
}
 
<!DOCTYPE html>
 
<html>
<head>
    <meta name="viewport" content="width=device-width"/>
    <title>Index</title>
</head>
<body>
    @Html.TextArea("Content", TempData["textcontent"])
</body>
</html>