The name 'ViewData' does not exist in the current context

谁都会走 提交于 2019-12-10 18:59:36

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/7744174/the-name-viewdata-does-not-exist-in-the-current-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!