In ASP.NET MVC project, the codebehind files(view.aspx.vb or view.aspx.cs) are not present. So first you'll need to add the code behind files as follows :
- Add new class(with same name as your view & vb extension) (e.g User.aspx.vb).
- Import
System.Web.Mvc
assembly to your class file.
- Inherit your class from ViewPage.
Go to your aspx page(view page), and edit it as follows :
<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="MvcApplication2.User" CodeBehind="User.aspx.vb" %>
- In order to attach code behind file with View, select both files ->right click->Exclude from Project. Then click Show All Files in Solutino Explorer Window. Again select these two files->right click->Include in Project.
- Add Page_Load even in your code behind file.
Your code behind file looks as follows:
Imports System.Web.Mvc
Public Class User Inherits ViewPage
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MsgBox("page Loaded")
End Sub
End Class