Asp.net Mvc Framework 3 (Controller and View)

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.