ASP.NET Learning - Initial MVC Project (1)

In this article, as a work tossing and turning, I started again and returned to the beginning of development, and I will show related learning articles one after another. I hope you can give me some opinions. Personally, I like to use VS. If you want to download it, please    download the relevant development software from https://msdn.itellyou.cn/ MSDN.

Below I will explain MVC with a small example.

1. First, we open the VS2012 new project, name it MvcDemo, click OK, and then select the Razor view engine.

The newly created project is as follows: The Account controller was added later by me.

2. We open Site.cs and replace the content with the following.

body
{
font: "Trebuchet MS", Verdana, sans-serif;
background-color: #5c87b2;
color: #696969;
}
h1
{
border-bottom: 3px solid #cc9900;
font: Georgia, serif;
color: #996600;
}
#main
{
padding: 20px;
background-color: #ffffff;
border-radius: 0 4px 4px 4px;
}
a
{
color: #034af3; 
}
/* Menu Styles ------------------------------*/ 
ul#menu
{
padding: 0px;
position: relative;
margin: 0;
}
ul#menu li
{
display: inline;
}
ul#menu li a 
{
background-color: #e8eef4;
padding: 10px 20px;
text-decoration: none;
line-height: 2.8em;
/*CSS3 properties*/
border-radius: 4px 4px 0 0;
}
ul#menu li a:hover
{
background-color: #ffffff;
} 
/* Forms Styles ------------------------------*/ 
fieldset
{
padding-left: 12px;
} 
fieldset label
{
display: block;
padding: 4px;
}
input[type="text"], input[type="password"]
{
width: 300px;
}
input[type="submit"]
{
padding: 4px;
}
/* Data Styles ------------------------------*/ 
table.data
{
background-color:#ffffff;
border:1px solid #c3c3c3;
border-collapse:collapse;
width:100%;
}
table.data th
{
background-color:#e8eef4;
border:1px solid #c3c3c3;
padding:3px;
}
table.data td 
{
border:1px solid #c3c3c3;
padding:3px;
}

Open _Layout and replace the contents with the following:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/modernizr-2.5.3.js")" type="text/javascript"></script>
</head>

<body>
<ul id="menu">
    <li>@Html.ActionLink("Home", "Index", "Home")</li>
    <li>@Html.ActionLink("Movies", "Index", "Movies")</li>
    <li>@Html.ActionLink("About", "About", "Home")</li>
</ul> 
<section id="main">
    @RenderBody()
    <p>Copyright RUNOOB 2012. All Rights Reserved.</p>
</section>
</body>
</html>

3. We add Index, About, and create a new view in the HomeController controller.

Write the content in the newly created Index:

@{ViewBag.Title = "Home Page";}

<h1>Welcome to runoob.com</h1>

<p>Put Home Page content here</p>

Write the content in the newly created About:

@{ViewBag.Title = "About Us";}

<h1>About Us</h1>

<p>Put About Us content here</p>

Then F5 runs.

This chapter ends here, and we will continue with the next chapter.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325172829&siteId=291194637