Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc Viewbag在当前上下文中不存在_Asp.net Mvc_Viewbag - Fatal编程技术网

Asp.net mvc Viewbag在当前上下文中不存在

Asp.net mvc Viewbag在当前上下文中不存在,asp.net-mvc,viewbag,Asp.net Mvc,Viewbag,我已经检查了所有可能的解决方案,比如清除缓存文件,更改SharedView文件夹的web.config文件中的版本号,但仍然无法在部分视图中解决此类问题 var count = parseInt('@Viewbag.FeedbackCount'); 有人能建议更好、更干净的解决方案,而不是将其标记为重复吗?这是JavaScript代码吗 如果是JavaScript,您可以执行以下操作 <input type="hidden" id="MyValue" value="@Viewbag.Fe

我已经检查了所有可能的解决方案,比如清除缓存文件,更改
Shared
View文件夹的
web.config
文件中的版本号,但仍然无法在部分视图中解决此类问题

var count = parseInt('@Viewbag.FeedbackCount');

有人能建议更好、更干净的解决方案,而不是将其标记为重复吗?

这是JavaScript代码吗

如果是JavaScript,您可以执行以下操作

<input type="hidden" id="MyValue" value="@Viewbag.FeedbackCount">
我也有类似的需求(但一定有更好的方法)

尝试使用

// these 2 lines
int count;
Int32.TryParse(ViewBag.FeedbackCount, out count))
// or just use one statemnt
int count= Int32.Parse(ViewBag.FeedbackCount);
如果上述方法无效,请尝试使用ViewData发送数据

int count = Int32.Parse(ViewData["FeedbackCount"]);

我认为他们中的一个应该做这个把戏。

这是
ViewBag
加了大写字母B,而不是
ViewBag

ViewBag只在Razor AFAIK中。你是用.cs还是.cshtml调用它?我用.cshtml调用它,
@Viewbag.FeedbackCount
的结果是什么?浏览器控制台中的错误消息是什么?(F12)为什么否决投票?怎么了?我在一些项目中使用了它。不是我的否决票,但OP使用的是javascript(在razor视图中),你使用的是C#Damn.。我不敢相信我在这方面浪费了2个小时:(@Steve我打赌你不会犯同样的错误两次;-)绝对不是mate
int count = Int32.Parse(ViewData["FeedbackCount"]);