Create new pages asp.net mvc
Here are the steps to create new pages in an ASP.NET MVC application:
Method 1: Using the "Add" menu
- Open your ASP.NET MVC project in Visual Studio.
- Right-click on the project in the Solution Explorer and select "Add" > "New Item...".
- In the "Add New Item" dialog box, select "ASP.NET MVC View Page" under the "Web" section.
- Name your new page (e.g., "About") and select a location to save it (e.g., "Views/Home").
- Click "Add" to create the new page.
Method 2: Using the "View" folder
- Open your ASP.NET MVC project in Visual Studio.
- Navigate to the "Views" folder in the Solution Explorer.
- Right-click on the folder and select "Add" > "New Folder" to create a new subfolder (e.g., "Home").
- Right-click on the new subfolder and select "Add" > "New Item...".
- In the "Add New Item" dialog box, select "ASP.NET MVC View Page" under the "Web" section.
- Name your new page (e.g., "About") and click "Add" to create the new page.
Creating a new page with a controller
If you want to create a new page with a corresponding controller, you can follow these steps:
- Create a new view page using one of the methods above.
- In the "Views" folder, navigate to the subfolder that corresponds to the controller you want to create (e.g., "Home").
- Right-click on the subfolder and select "Add" > "New Item...".
- In the "Add New Item" dialog box, select "Controller" under the "Web" section.
- Name your new controller (e.g., "HomeController") and click "Add" to create the new controller.
- In the new controller, add an action method that corresponds to the new view page (e.g., "About").
- In the action method, return the new view page using the
View()
method (e.g.,return View();
).
For example, if you created a new view page called "About.cshtml" in the "Views/Home" folder, you would create a new controller called "HomeController.cs" in the "Controllers" folder with an action method like this:
public class HomeController : Controller
{
public ActionResult About()
{
return View();
}
}
This will render the "About.cshtml" view page when the user navigates to the /Home/About
URL.