Wednesday 29 January 2014

MVC 4 - Rendering web Pages

Leave a Comment
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 =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.