MVC 4 - Rendering web Pages

The output from the previous post wasn’t HTML—it was just the string "Hello World, This is my first MVC Application". To produce an HTML response to a browser request, we need to create a view.

Creating And Rendering a View

  1. Modify the Controller to render a View (please refer the previous post before you do this).
  2.  
            public ViewResult Index()
            {
                return View();
            }

  3. Right click at word View() and choose Add View
  4. Leave the devault value and click Add button
  5. Congratulation, now you have successfully created new view which will be rendered as html when the root / or  /Home or /Home/Index url hit
Note : The .cshtml file extension denotes a C# view that will be processed by Razor.

Now copy this HTML code on the Index.cshtml file.
@{
    ViewBag.Title = "Index";
}

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
Hello World (This is render from the view).
</div>
</body>
</html>




By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

Popular posts from this blog

Example to disable save as certain file type in SSRS Report Viewer

Phone book application example - Java

Modal Popup Message Box ASP.NEt C# Example