如何在ASP.NET mvc4中添加新页面?

时间:2021-02-06 16:58:06

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.

我想创建一个新项目,我想添加一个新页面,使用Microsoft示例网站作为起点。 Microsoft示例网站已有一个About和a Contact页面。

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

如何使用ASP.NET mvc4将新页面添加到示例网站?

1 个解决方案

#1


12  

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:

在ASP.NET MVC中,您使用模型,控制器和视图。控制器是包含名为Actions的方法的类。每个Action都用作给定用户请求的入口点。此操作将使用模型执行任何必要的处理并返回视图。所以基本上你将开始定义一个Controller(如果还没有完成)并向它添加Actions:

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.

然后右键单击Action名称并选择Add-> View选项,它将在相应的〜/ Views文件夹中为给定的Action创建一个新视图。

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

我建议您先阅读这里的基本教程:http://asp.net/mvc

#1


12  

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:

在ASP.NET MVC中,您使用模型,控制器和视图。控制器是包含名为Actions的方法的类。每个Action都用作给定用户请求的入口点。此操作将使用模型执行任何必要的处理并返回视图。所以基本上你将开始定义一个Controller(如果还没有完成)并向它添加Actions:

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.

然后右键单击Action名称并选择Add-> View选项,它将在相应的〜/ Views文件夹中为给定的Action创建一个新视图。

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

我建议您先阅读这里的基本教程:http://asp.net/mvc