我正在尝试计算从linq返回到sql的行的数量,并将其值从控制器传递到viewBag查看,但是它给出了错误无法转换类型' int'到'字符串'
查看
@Html.Label((string)ViewBag.totalSpaces)
控制器
List<RentOutSpace> parkingSpaces = searchModel.searchSpace(address);
int count = parkingSpaces.Count();
string countSpace = count.ToString();
ViewBag.totalSpaces = countSpace;
答案 0 :(得分:1)
试试这个:
@Html.Label(ViewBag.totalSpaces)
答案 1 :(得分:1)
您不需要使用@ Html.Label
只需使用
@ViewBag.totalSpaces
或者 Html.Label((字符串)@ ViewBag.totalSpaces)
这应该有效