Upgrade MVC 2 to MVC 3 issues with views

落花浮王杯 提交于 2019-12-07 08:12:09

问题


I'm attempting to upgrade my existing ASP.net MVC 2 web application to MVC 3 so I can use the goodness that is the Razor Viewengine and other said improvements.

After using the converter to convert my app from mvc2 to mvc3 I'm having issues with my strongly typed views. As an example here we have a view user control that is strongly typed to the class Profile

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Profile>" %>

During compilation I'm getting

Compiler Error Message: CS1061: 'object' does not contain a definition for 'folio' and no extension method 'folio' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

which corresponds to this line in my view

So it's like the views are no longer accepting a type. This is happening w/ user controls as well as full on views.

I've checked both web.config and views/web.config and both seem to be referencing System.Web.Mvc version 3.0.0.0

Any help would be appreciated!

See below for screen captures of web.configs


回答1:


This is a bug in MVC 3 Preview 1, and will be addressed in the next release. In the interim, you can rearrange your pages so that the <%@ Control %> directive is the last one in the file and that should the issue for you.




回答2:


I simply replaced the web.config in my 'Views' folder (with one from a newly created mvc3 project) as the migration suggested and it worked for me. I wasn't prepared to move all the declarations to the bottom as my project was just too big.

Hope it helps although this is probably too late for you. Maybe it helps others...




回答3:


On the off chance try changing your bindingRedirect to

<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />



回答4:


I had the exact same problem and after pulling my hair out a bit, found and followed Wiaan's solution. Worked perfectly, and the site is back up.

Funny enough not making this change on our dev boxes did not break our site - it was only when we moved it to a staging server that it surfaced.




回答5:


If your project is based on MVC4 or using Framwork 4 already, create mvc4 empty project. And then replace web.config in views folder. It works immediately. Thanks, Wianne. Since I have kind of old app that used aspx rather than razor. After I upgraded Framework 3 to 4, I got this error.



来源:https://stackoverflow.com/questions/3516130/upgrade-mvc-2-to-mvc-3-issues-with-views

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