名称“ViewData”当前上下文中不存在
我正在开发我的第一个基于 MVC3 的应用程序,但仍然是一个新手:
我试图在母版页上成功我的 ViewData[],因为它包含一条将在每个页面上使用的消息,但是当我尝试访问它时,它显示:
CS0103:名称“ViewData”确实在当前上下文中不存在
var msg = ViewData["msg"] as string;
//var msg = ViewBag.msg as string;
if (msg != null)
{
Response.Write (msg);
} else if (msg == null)
{
Response.Write("");
}
我不确定我是否做错了什么,或者只是无法通过我的 MasterPage 访问 ViewData[]。请帮忙!
I am working over my first application over MVC3 and still kind of a newbie in it:
I’m trying to success my ViewData[] over a master page because its contains a message that would be used over every page, but when I’m trying to access that it says:
CS0103: The name 'ViewData' does not exist in the current context
var msg = ViewData["msg"] as string;
//var msg = ViewBag.msg as string;
if (msg != null)
{
Response.Write (msg);
} else if (msg == null)
{
Response.Write("");
}
I am not sure whether I’m doing something wrong or it’s just not possible to access ViewData[] over my MasterPage. Help please!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将母版页设置为继承
System.Web.Mvc.ViewMasterPage
。You need to set your master page to inherit
System.Web.Mvc.ViewMasterPage
.