且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET MVC"转换为Web申请表]选项​​缺少在Visual Studio

更新时间:2023-02-17 09:51:46

转换为Web应用程序是一个项目/文件级别的命令。你不能把它用在一个 ASPX 文件。

此外,别无他法自动化的方式(即我知道:-)),以code隐藏文件添加到一个ASPX文件。你必须做手工,自己加入相关文件,然后将其添加到.csproj的。

I'm working with Visual Studio 2008 SP1 and ASP.NET MVC v1. When right clicking on a view I do not get the option "Convert to Web Application" that I would need to generate code behind .cs classes. I see that option for the actual project and folders, but not for views (aspx files). I've checked the ProjectTypeGuids to have the "right" (?) values:

{603c0e0b-db56-11dc-be95-000d561079b0};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}

Any other suggestions as to what I could look for?

Thanks.

(I am aware of design implications of using code behind classes with MVC)

P.S. To do it manually all you have to do is:

  1. Add a file with the same name as your view and the .cs (or .vb) extension, for example Index.aspx.cs. Make sure you modify your class to inherit from System.Web.Mvc.ViewPage or some other class that inherits from that.
  2. Edit the aspx file and add to the @Page directive CodeBehind="Index.aspx.cs" and change Inherits to "MyNamespace.Views.Home.Index" (obviously you need to have the right code behind and namespace there).
  3. Right click on the aspx file and choose Convert to Web Application. This will create the design file and also modify your .cs class and mark it as "partial".

"Convert to web application" is a project/file-level command. You can't use it on a single ASPX file.

Also, there is no alternative automated way (that I know of :-)) to add code-behind files to an ASPX file. You have to do it manually, by adding the relevant files yourself and then adding them to the .csproj.