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,
namespace MvcApplication1.Models
{
public class Student
{
public int rollnumber { set; get; }
public string firstname { set; get; }
public string lastname { set; get; }
}
}
Student Controller as,
using MvcApplication1.Models;
namespace MvcApplication1.Controllers
{
public class StudentController : Controller
{
public ActionResult Index()
{
Student std = new Student();
std.rollnumber = 1;
std.firstname = "Sujata";
std.lastname = "Garad";
return View(std);
}
}
}
And My Index.aspx as,
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,
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new {
controller = "Student",
action = "Index",
id = "" }
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}
}
Then i just press f5 key then it gives error like
Server Error in '/' Application.
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.