{"id":234046,"date":"2022-01-22T10:25:02","date_gmt":"2022-01-22T02:25:02","guid":{"rendered":"https:\/\/gulass.cn\/?p=234046"},"modified":"2022-01-08T18:27:00","modified_gmt":"2022-01-08T10:27:00","slug":"styles-and-layouts","status":"publish","type":"post","link":"https:\/\/gulass.cn\/styles-and-layouts.html","title":{"rendered":"ASP.NET MVC – \u6837\u5f0f\u548c\u5e03\u5c40\u7b80\u4ecb"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nMVC \u662f\u4e09\u79cd ASP.NET \u7f16\u7a0b\u6a21\u5f0f\u4e2d\u7684\u4e00\u79cd\u3002MVC \u662f\u4e00\u79cd\u4f7f\u7528 MVC\uff08Model View Controller \u6a21\u578b-\u89c6\u56fe-\u63a7\u5236\u5668\uff09\u8bbe\u8ba1\u521b\u5efa Web \u5e94\u7528\u7a0b\u5e8f\u7684\u6a21\u5f0f.<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u6dfb\u52a0\u5e03\u5c40<\/strong><\/div>\n

\u6587\u4ef6 _Layout.cshtml \u8868\u793a\u5e94\u7528\u7a0b\u5e8f\u4e2d\u6bcf\u4e2a\u9875\u9762\u7684\u5e03\u5c40\u3002\u5b83\u4f4d\u4e8e Views \u6587\u4ef6\u5939\u4e2d\u7684 Shared \u6587\u4ef6\u5939\u3002<\/p>\n

\u6253\u5f00\u6587\u4ef6 _Layout.cshtml\uff0c\u628a\u5185\u5bb9\u66ff\u6362\u6210\uff1a<\/p>\n

<!DOCTYPE html>
<html>
<head>
<meta charset=\"utf-8\" \/>\r\n<title>@ViewBag.Title<\/span><\/title>
<link href=\"@Url.Content(\"~\/Content\/Site.css\")<\/span>\" rel=\"stylesheet\" type=\"text\/css\" \/>
<script src=\"@Url.Content(\"~\/Scripts\/jquery-1.5.1.min.js\")<\/span>\"><\/script>
<script src=\"@Url.Content(\"~\/Scripts\/modernizr-1.7.min.js\")<\/span>\"><\/script>
<\/head>
<body>
<ul id=\"menu\">\r\n<li>@Html.ActionLink(\"Home\", \"Index\", \"Home\")<\/span><\/li>
<li>@Html.ActionLink(\"Movies\", \r\n\"Index\", \"Movies\")<\/span><\/li>
<li>@Html.ActionLink(\"About\", \"About\", \r\n\"Home\")<\/span><\/li>
<\/ul>
<section id=\"main\">
@RenderBody()<\/span>\r\n<p>Copyright RUNOOB 2012. All Rights Reserved.<\/p>
<\/section>
<\/body>
<\/html><\/pre>\n
HTML \u5e2e\u52a9\u5668<\/strong><\/div>\n

\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0cHTML \u5e2e\u52a9\u5668\u7528\u4e8e\u4fee\u6539 HTML \u8f93\u51fa\uff1a<\/p>\n

@Url.Content() - URL \u5185\u5bb9\u5c06\u5728\u6b64\u5904\u63d2\u5165\u3002<\/p>\n

@Html.ActionLink() - HTML \u94fe\u63a5\u5c06\u5728\u6b64\u5904\u63d2\u5165\u3002<\/p>\n

\u5728\u672c\u6559\u7a0b\u540e\u9762\u7684\u7ae0\u8282\u4e2d\uff0c\u60a8\u5c06\u5b66\u5230\u66f4\u591a\u5173\u4e8e HTML \u5e2e\u52a9\u5668\u7684\u77e5\u8bc6\u3002<\/p>\n

Razor \u8bed\u6cd5<\/strong><\/div>\n

\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u7ea2\u8272\u6807\u8bb0\u7684\u4ee3\u7801\u662f\u4f7f\u7528 Razor \u6807\u8bb0\u7684 C#\u3002<\/p>\n

@ViewBag.Title - \u9875\u9762\u6807\u9898\u5c06\u5728\u6b64\u5904\u63d2\u5165\u3002<\/p>\n

@RenderBody() - \u9875\u9762\u5185\u5bb9\u5c06\u5728\u6b64\u5904\u5448\u73b0\u3002<\/p>\n

\u60a8\u53ef\u4ee5\u5728\u6211\u4eec\u7684 Razor \u6559\u7a0b\u4e2d\u5b66\u4e60\u5173\u4e8e C# \u548c VB\uff08Visual Basic\uff09\u7684 Razor \u6807\u8bb0\u7684\u77e5\u8bc6\u3002<\/p>\n

\u6dfb\u52a0\u6837\u5f0f<\/strong><\/div>\n

\u5e94\u7528\u7a0b\u5e8f\u7684\u6837\u5f0f\u8868\u662f Site.css\uff0c\u4f4d\u4e8e Content \u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n

\u6253\u5f00\u6587\u4ef6 Site.css\uff0c\u628a\u5185\u5bb9\u66ff\u6362\u6210\uff1a<\/p>\n

body
{
font: \"Trebuchet MS\", Verdana, sans-serif;
background-color: \r\n#5c87b2;
color: #696969;
}
h1
{
border-bottom: 3px solid \r\n#cc9900;
font: Georgia, serif;
color: #996600;
}
#main
{\r\npadding: 20px;
background-color: #ffffff;
border-radius: 0 4px 4px \r\n4px;
}
a
{
color: #034af3;
}
\/* Menu Styles \r\n------------------------------*\/
ul#menu
{
padding: 0px;\r\nposition: relative;
margin: 0;
}
ul#menu li
{
display: \r\ninline;
}
ul#menu li a
{
background-color: #e8eef4;
padding: \r\n10px 20px;
text-decoration: none;
line-height: 2.8em;
\/*CSS3 \r\nproperties*\/
border-radius: 4px 4px 0 0;
}
ul#menu li a:hover
{\r\nbackground-color: #ffffff;
}
\/* Forms Styles \r\n------------------------------*\/
fieldset
{
padding-left: 12px;\r\n}
fieldset label
{
display: block;
padding: 4px;
}\r\ninput[type=\"text\"], input[type=\"password\"]
{
width: 300px;
}\r\ninput[type=\"submit\"]
{
padding: 4px;
}
\/* Data Styles \r\n------------------------------*\/
table.data
{
background-color:#ffffff;\r\nborder:1px solid #c3c3c3;
border-collapse:collapse;
width:100%;
}\r\ntable.data th
{
background-color:#e8eef4;
border:1px solid #c3c3c3;\r\npadding:3px;
}
table.data td
{
border:1px solid #c3c3c3;\r\npadding:3px;
}<\/pre>\n
_ViewStart \u6587\u4ef6<\/strong><\/div>\n

Shared \u6587\u4ef6\u5939\uff08\u4f4d\u4e8e Views \u6587\u4ef6\u5939\u5185\uff09\u4e2d\u7684 _ViewStart \u6587\u4ef6\u5305\u542b\u5982\u4e0b\u5185\u5bb9\uff1a<\/p>\n

@{Layout = \"~\/Views\/Shared\/_Layout.cshtml\";}<\/pre>\n

\u8fd9\u6bb5\u4ee3\u7801\u88ab\u81ea\u52a8\u6dfb\u52a0\u5230\u7531\u5e94\u7528\u7a0b\u5e8f\u663e\u793a\u7684\u6240\u6709\u89c6\u56fe\u3002<\/p>\n

\u5982\u679c\u60a8\u5220\u9664\u4e86\u8fd9\u4e2a\u6587\u4ef6\uff0c\u5219\u5fc5\u987b\u5411\u6240\u6709\u89c6\u56fe\u4e2d\u6dfb\u52a0\u8fd9\u884c\u4ee3\u7801\u3002<\/p>\n

\u5728\u672c\u6559\u7a0b\u540e\u9762\u7684\u7ae0\u8282\u4e2d\uff0c\u60a8\u5c06\u5b66\u5230\u66f4\u591a\u5173\u4e8e\u89c6\u56fe\u7684\u77e5\u8bc6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u6587\u4ef6 _Layout.cshtml \u8868\u793a\u5e94\u7528\u7a0b\u5e8f\u4e2d\u6bcf\u4e2a\u9875\u9762\u7684\u5e03\u5c40\u3002\u5b83\u4f4d\u4e8e Views \u6587\u4ef6\u5939\u4e2d\u7684 Shared […]<\/p>\n","protected":false},"author":1470,"featured_media":234048,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-234046","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/234046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=234046"}],"version-history":[{"count":3,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/234046\/revisions"}],"predecessor-version":[{"id":234051,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/234046\/revisions\/234051"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/234048"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=234046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=234046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=234046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}