Simple HTML Asp.Net MVC Page

In my previous post, you learn the how to display text in Asp.Net MVC. In this post I will explain how to render simple HTML page in Asp.Net MVC.


Open Visual studio 2008 Framework.  Go to File -> New -> Project.
Name the project name as SimpleHTMLMVCPage. Delete unnecessary files as mentioned below.


To delete the unnecessary files, Open Solution Explorer and select the files mention below.

App_Data folder, AccountController.cs controller from Controllers Folder, Account  folder from Views folder ,  About.aspx and Index pages from Home folder in the Views folder and all files from Shared folder in the Views folder.

 

You can delete above files individually by right click on each file and select Delete.


Open HomeController.cs controller from Controller folder and delete all code inside the HomeController class and place your own code shown below.


public class HomeController : Controller
    {
        public ViewResult Index()
        {
            return View();
        }
    }

In the HomeController class you are returning object type of ViewResult, which means you are giving the MVC Framework to render a View. In Asp.Net MVC Framework Views are responsible for rendering the HTML content.


Now you have to add a view for Index action method. To add a view for Index action method, right click on Index() method select Add View as shown below.

 

 

 


After selecting the Add View, there is a small popup window will display. In that window uncheck “Select master page” checkbox because you are not using any master page here and click Add as shown below

 

 


By clicking Add, MVC Framework will create Index.aspx for Home folder in Views Folder. It is looking like a normal HTML page, you can write anything in the <body> tag. I write the some text as given below.

<body>
    <div>
        This is From View, showing rendering the HTML content
    </div>
</body>

Press F5, the Browser will display same content what you write in between <body> tags.

In my previous post we display the simple text, but here we render the HTML page. If you want check, go to View Source of Browser then you will find the HTML code for the page.

As I said in my previous post, Controllers will handle incoming requests and action methods of Controller will execute respective View by returning the ViewResult Object

For Source code for the above post SimpleHTMLMVCPage.zip (253.76 kb)

 

In my next post, I will explain how to create simple registration form in Asp.Net MVC.