[MVC4] First knowledge of. NET MVC4

Source: Internet
Author: User

The last one months have been concentrating on the game of Unity3d landlords, from morning till night, finally came out, the sadness of which only their own know. Recently had the time to be idle, or to study the old line before the--asp.net, now use. NET to do project popular MVC, rather than the previous three layer, since the technology in the update, can only continue to learn to adapt to the new technology trend!

Create an MVC project1. Open Visual studio2012, new MVC4 project2. Select Project properties to create an MVC project3. Catalog of generated projects
    • App_start: Configuration information for startup files, including important Routeconfig routing registration information
    • Content file Placement Style file
    • Controllers folder to place the controller
    • The Scripts folder system automatically creates jquery files
    • Views folder Place the controller's view file
4.RouteConfig File [CSharp]View Plaincopyprint?
  1. <span style= "FONT-SIZE:14PX;" >routes. MapRoute (
  2. Name: "Default",
  3. URL: "{controller}/{action}/{id}" , under//controller directory, action match controllers directory under ActionResult, ID is a writable parameter
  4. Defaults: new {controller = "Home", action = "Index", id = urlparameter . Optional} //Index under Default startup item HomeController
  5. );</span>
This file is a route registration file that configures the default startup entry, where the controller specified here is Homecontroller,actionresult is index,id writable. 5. New Controllerin the Controllers folder, right-click Add----Controller, keep controllers, name HomeController

Click Add to create the success. View the generated HomeController controller [CSharp]View Plaincopyprint?
    1. Public actionresult Next ()
    2. {
    3. return  View ();
    4. }

This returns a actionresult to the foreground view page, where we can create a controller view based on this.6. New Controller ViewIn the above ActionResult, right click on the mouse, add the view, the name should be consistent with the method name. And then automatically generate a view of the controller under the Views folder. Microsoft is too sweet, wow, click!7. Add code to the controller and display it in the viewWe add the following code in the controller index method, which is passed to the view [CSharp]View Plaincopyprint?
  1. Public actionresult Index ()
  2. {
  3. Viewbag.joy = "Name:";
  4. Viewbag.name = "ding small not";
  5. viewdata["Data"= "Let's learn to learn ASP. MVC4!"  ";
  6. return  View ();
  7. }

Front View Display method [CSharp]View Plaincopyprint?
    1. @{
    2. Viewbag.title = "Index";
    3. }
    4. <a href="http://blog.csdn.net/dingxiaowei2013"> Lifelong Learning column </a>
    5. <br/>
    6. @ViewBag. Joy
    7. <br/>
    8. @ViewBag. Name
    9. <br/>
    10. @ViewData ["Data"]

8. View the effect of the operationbecause of the default route registration, these two URL effects are the same.


If we run the other view it is also possible to access the Nextaction view under HomeController


You can also access the action view of other controllers


Welcome to watch my scarf.

==================== csdn Blog Column =================

myblog:http://blog.csdn.net/dingxiaowei2013 myqq:1213250243

Unity QQ Group:375151422,858550,6348968 cocos2dx QQ Group: 280818155

====================== learn from each other and progress together ===================

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.