Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a new page in ASP.NET mvc4?

I want to make a new project and I want to add a new page, using the Microsoft sample website as a starting point. The Microsoft sample website already has an About and a Contact page.

How do I add a new page to the sample website using ASP.NET mvc4?

like image 309
Dashang Avatar asked Jul 27 '12 05:07

Dashang


People also ask

How do you add a view on razor?

Right click the Views\HelloWorld folder and click Add, then click MVC 5 View Page with Layout (Razor). In the Specify Name for Item dialog box, enter Index, and then click OK. In the Select a Layout Page dialog, accept the default _Layout. cshtml and click OK.

Can we have ASPX page in MVC?

If you add a plain ASPX page to an ASP.NET MVC project, well, it just works like a charm without any changes to the configuration. If you invoke the ASPX page, the ASPX page is processed with viewstate and postbacks.


1 Answers

In ASP.NET MVC you work with Models, Controllers and Views. Controllers are classes containing methods called Actions. Each Action is used as an entry point for a given user request. This Action will perform any necessary processing with the model and return a view. So basically you will start with defining a Controller (if not already done) and add Actions to it:

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

    public ActionResult SomeAction()
    {
        return View();
    }
}

Then you right click on the Action name and select the Add->View option which will create a new View for the given Action in the respective ~/Views folder.

I would recommend that you start by going through the basic tutorials here: http://asp.net/mvc

like image 71
Darin Dimitrov Avatar answered Sep 19 '22 09:09

Darin Dimitrov