Click here to Skip to main content
15,887,294 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,
I am Sujata .I am new to Web application development using MVC2.Here I have created Sample asp.net empty Mvc2 we application as MvcApplication1 with Student.cs as Model ,StudentController as controller and Index as view.
Here My Student.cs as follows,
C#
namespace MvcApplication1.Models
{
    public class Student
    {
        public int rollnumber { set; get; }
        public string firstname { set; get; }
        public string lastname { set; get; }
    }
}


Student Controller as,

C#
using MvcApplication1.Models;

namespace MvcApplication1.Controllers
{
    public class StudentController : Controller
    {
        //
        // GET: /Student/

        public ActionResult Index()
        {
            Student std = new Student();
            std.rollnumber = 1;
            std.firstname = "Sujata";
            std.lastname = "Garad";
            return View(std);
        }

    }
}


And My Index.aspx as,

ASP.NET
 Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.Student>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Index</title>
</head>
<body>
    <div>
    Student Rollnumber is <%=Model.rollnumber %>
    Student FirstName is<%=Model.firstname %>
    Student LastName is<%=Model.lastname %>
    
    </div>
</body>
</html>


And My Global.aspx file is as,
C#
public class MvcApplication : System.Web.HttpApplication
   {
       public static void RegisterRoutes(RouteCollection routes)
       {
           routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

           routes.MapRoute(
               "Default", // Route name
               "{controller}/{action}/{id}", // URL with parameters
               new {
                   controller = "Student",
                   action = "Index",
                   id = "" } // Parameter defaults
           );

       }

       protected void Application_Start()
       {
           AreaRegistration.RegisterAllAreas();

           RegisterRoutes(RouteTable.Routes);
       }
   }


Then i just press f5 key then it gives error like
JavaScript
Server Error in '/' Application.

C#
The view 'Index' or its master was not found. The following locations were searched:
~/Views/Student/Index.aspx
~/Views/Student/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx 



Please give me solution.

thanks.
Posted
Comments
Sinisa Hajnal 8-Jan-16 6:27am    
Is your Index in Views/Student or Views/shared folders? If not, why not? You see it is looking for it there.
SujataJK 8-Jan-16 6:57am    
No my Index is as Views/Index.aspx .
SujataJK 8-Jan-16 7:01am    
Thanks Sinisa .
I solved my problem when i put my Index View under Views/Shared Folder.
thanks again for your early response.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900