名称"ViewData"在当前上下文中不存在 [英] The name 'ViewData' does not exist in the current context

查看:581
本文介绍了名称"ViewData"在当前上下文中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过MVC3处理我的第一个应用程序,并且仍然是其中的一个新手:
我正在尝试通过母版页成功完成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:名称"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("");
        }

我不确定我是在做错什么,还是无法通过我的母版页访问ViewData [].请帮忙!

I am not sure whether I’m doing something wrong or it’s just not possible to access ViewData[] over my MasterPage. Help please!

推荐答案

您需要将母版页设置为继承System.Web.Mvc.ViewMasterPage.

You need to set your master page to inherit System.Web.Mvc.ViewMasterPage.

这篇关于名称"ViewData"在当前上下文中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆