I notice with the latest version of ASP.NET MVC that a View no longer defaults to having code-behind classes.
How do I go about adding a code-behind class now to a
To add a codebehind file to your aspx page, while still allowing it to be the target of an MVC view, do the following.
For a view page named Index.aspx
...
Replace the following code....
<%@ Page Inherits="System.Web.Mvc.ViewPage" %>
with
<%@ Page CodeFile="Index.aspx.vb" Inherits="Home_Index" %>
Then create a file called Index.aspx.cs
(or .vb
).
partial class Home_Index : System.Web.Mvc.ViewPage
{...}
or VB
Partial Class Home_Index
Inherits System.Web.Mvc.ViewPage
...
End Class
That's it. The only thing special is using the correct Mvc.ViewPage
base class.