小编jbq*_*jbq的帖子

ASP.NET MVC5从布局访问ViewBag?

我正在尝试将动态数据从我的控制器传递到我的视图和布局.我目前正在使用ViewBag将数据从Controller传递到视图,该视图工作正常.我无法从布局中访问ViewBag.有没有办法做到这一点?

我正在使用ASP.NET W/MVC5(C#).

编辑:更新了W /代码:

//layout.cshtml
@ViewBag.username
Run Code Online (Sandbox Code Playgroud)

产生此错误:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'ViewBag' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc

5
推荐指数
1
解决办法
1万
查看次数

SQL内部联接,其中记录不存在

我目前有两个表,我正在使用INNER JOIN子句查询.我的第一个标记为departments的表非常简单,只包含3个字段--deptID,deptName和companyID.我的第二个标记为departmentMemberships的表更简单,只包含2个字段--deptID和employeeID.我当前的SQL语句查询这两个表并返回所有deptID,deptName和每个部门的员工数.如果上述部门中没有任何员工,我的查询将不会返回部门.这是我目前的查询.

`SELECT departments.deptID, departments.deptName,
COUNT(departmentMemberships.deptID) AS employeeCount
FROM departmentMemberships
INNER JOIN departments
ON departmentMemberships.deptID = departments.deptID
WHERE departments.companyID = 1
GROUP BY departments.deptID, departments.deptName
ORDER BY departments.deptName ASC;`
Run Code Online (Sandbox Code Playgroud)

请原谅我对TSQL的经验不足,但我怎么能改变这个查询以返回所有部门,包括没有员工注册的部门?

非常感谢你

sql t-sql sql-server

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net-mvc ×1

c# ×1

sql ×1

sql-server ×1

t-sql ×1