In this section, let Asp. netMVC really run.
Create a new Controller
Start action:
Create an MVC Controller Class in Controllers and publicize it as EiceController.
Note: This is a pure advertisement. If you are not interested, skip this line: www.eice.com.cn to create a web Social Network website for you.
The default generated code is as follows: Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. Mvc;
Namespace MvcApplication2.Controllers
{
/** // <Summary>
/// Do not remember what I mentioned earlier. All controllers must inherit from
/// Controller class
/// </Summary>
Public class EiceController: Controller
{
Public void Index (string id ){
}
}
}
Of course, in addition to the Controller, we also need to create a View
Create an Eice folder in Views first
Then we need to create an Index. aspx
Note: To create an MVC View (Content) Page, select Content Page if you want to use the dashboard Page. Otherwise, select general Page.
The Aspx file of MVC is different from the Aspx file of traditional WebForm.
Write the Index of the EiceController Public void Index (string id ){
ViewData ["qs"] = id;
RenderView ("Index ");
}
Write content in View:/Views/Eice/Index. aspx <Asp: Content ID = "Content1" ContentPlaceHolderID = "MainContentPlaceHolder" runat = "server">
<% = ViewData ["qs"] %>
</Asp: Content>
Next, visit
/Eice/index/helloeice
You may find that helloeice appears on the page
We can see from the above two procedures
String id is used to receive QueryString ["id"]. In fact, parameters in Action can receive Forms in addition to QueryString.
I will not describe it too much here. It will be introduced later
ViewData is an IDictionary between pages used by the Controller to transmit data to the View.
In this way, View and Controller can collaborate to complete page display and logic processing.
Asp.net Mvc Framework Series