{"id":561,"date":"2021-06-16T23:21:49","date_gmt":"2021-06-16T23:21:49","guid":{"rendered":"https:\/\/turtleflyblog.com\/?p=561"},"modified":"2022-02-28T09:20:18","modified_gmt":"2022-02-28T09:20:18","slug":"custom-view-engine-2","status":"publish","type":"post","link":"https:\/\/turtleflyblog.com\/zh\/2021\/06\/16\/custom-view-engine-2\/","title":{"rendered":"Custom View Engine"},"content":{"rendered":"\n
\u5728ASP.NET MVC\u88e1\u6bcf\u500bController\u53ef\u4ee5\u6709\u597d\u5e7e\u500bAction, \u800c\u6bcf\u500bAction\u7684\u7d50\u679c\u5f88\u53ef\u80fd\u5c31\u662fView\u3002\u5176\u4e2d\u8ca0\u8cacView\u55a7\u67d3\u52d5\u4f5c\u7684\u5c31\u662fView Engine\u3002\u6211\u5011\u5148\u4f86\u770b\u6574\u500bView Result\u57f7\u884c\u904e\u7a0b<\/p>\n\n\n\n \u7531\u4e0a\u5716\u53ef\u77e5\u9053View\u6703\u9078\u64c7\u9810\u8a2d\u7684View\u8def\u5f91\uff0c\u82e5\u6c92\u627e\u5230\u7b2c\u4e8c\u500b\u9810\u8a2d\u7684View\u7684\u8def\u5f91\u76f4\u5230\u627e\u5230\u70ba\u6b62\u3002<\/p>\n\n\n\n \u7576\u6574\u500b\u5c08\u6848\u67b6\u69cb\u8981\u8abf\u6574\u3002View\u8def\u5f91\u4f4d\u5740\u56e0\u6b64\u8981\u8abf\u6574\u5230\u7b26\u5408\u5c08\u6848\u7684\u65b0\u8def\u5f91\uff0c\u6b64\u6642\u5c31\u9700\u8981Custom View Engine\u3002\u672c\u7bc7\u6703\u4ecb\u7d39\u5982\u4f55\u8abf\u6574View\u9810\u8a2d\u8def\u5f91\u5728ASP.NET MVC\u548cASP.NET CORE<\/p>\n\n\n\n ASP.NET CORE<\/strong><\/p>\n\n\n\n \u5728StartUp.cs\u88e1\u7684ConfigureServices\u65b9\u6cd5\u88e1\u52a0\u4e0a\u4e0a\u8ff0\u9019\u6bb5\u7a0b\u5f0f\u78bc\u3002\u8a18\u5f97\u5728AddRazorOptions\u88e1\u8981\u7528Insert\u800c\u4e0d\u8981\u7528Add\u3002Insert\u6703\u52a0\u5728\u9810\u8a2dView\u8def\u5f91\u4e4b\u524d\uff0c\u800cAdd\u6703\u52a0\u5728\u9810\u8a2dView\u8def\u5f91\u4e4b\u5f8c\u3002<\/p>\n\n\n\n \u5728Theme\u8cc7\u6599\u593e\u7522\u51facshtml\u6a94\uff0c\u63a5\u8005\u6309\u57f7\u884c\u9801\u9762\u5c31\u61c9\u6703\u512a\u5148\u7522\u51fa\u5728Theme\u8cc7\u6599\u593e\u5e95\u4e0b\u7684cshtml\u6a94\u4e86\u3002<\/p>\n\n\n\n \u57f7\u884c\u756b\u9762\u70ba<\/p>\n\n\n\n ASP.NET MVC<\/strong><\/p>\n\n\n\n \u5efa\u7acb\u4f60\u7684Custom View Engine\u985e\u5225\u3002\u82e5\u9078\u64c7\u65b0\u7684View\u70baRazor\u985e\u578b\uff0c\u4f60\u7684\u65b0view engine class\u7e7c\u627fRazorViewEngine\u3002<\/p>\n\n\n\n \u63a5\u8005\u5728Global.asax\u88e1\uff0c\u5982ASP.NET CORE\u52a0\u4e0aView Engine\u9019\u884c\u7a0b\u5f0f\u78bc\u3002<\/p>\n\n\n\n \u9069\u7576\u4f7f\u7528Custom View Engine\u53ef\u5e6b\u6211\u5011\u5ba2\u88fd\u5316\u6574\u500b\u5c08\u6848\u7684\u67b6\u69cb\u3002\u5b78\u7fd2Custom View Engine\u4e26\u4e0d\u7b97\u96e3\u3002ASP.NET MVC\u6574\u500b\u67b6\u69cb\u4e5f\u6709\u8a31\u591a\u53ef\u4ee5\u5ba2\u88fd\u5316\u7684\u5730\u65b9\uff0c\u6709\u52a9\u65bc\u9054\u5230\u6574\u500b\u5718\u968a\u8981\u7684\u61c9\u7528\u76ee\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":" \u5728ASP.NET MVC\u88e1\u6bcf\u500bController\u53ef\u4ee5\u6709\u597d\u5e7e\u500bAction, \u800c\u6bcf\u500bAction\u7684\u7d50\u679c\u5f88\u53ef\u80fd\u5c31\u662fView\u3002\u5176\u4e2d\u8ca0\u8cacView\u55a7\u67d3\u52d5\u4f5c\u7684\u5c31\u662fView Engine\u3002\u6211\u5011\u5148\u4f86\u770b\u6574\u500bView Result\u57f7\u884c\u904e\u7a0b \u7531\u4e0a\u5716\u53ef\u77e5\u9053View\u6703\u9078\u64c7\u9810\u8a2d\u7684View\u8def\u5f91\uff0c\u82e5\u6c92\u627e\u5230\u7b2c\u4e8c\u500b\u9810\u8a2d\u7684View\u7684\u8def\u5f91\u76f4\u5230\u627e\u5230\u70ba\u6b62\u3002 \u7576\u6574\u500b\u5c08\u6848\u67b6\u69cb\u8981\u8abf\u6574\u3002View\u8def\u5f91\u4f4d\u5740\u56e0\u6b64\u8981\u8abf\u6574\u5230\u7b26\u5408\u5c08\u6848\u7684\u65b0\u8def\u5f91\uff0c\u6b64\u6642\u5c31\u9700\u8981Custom View Engine\u3002\u672c\u7bc7\u6703\u4ecb\u7d39\u5982\u4f55\u8abf\u6574View\u9810\u8a2d\u8def\u5f91\u5728ASP.NET MVC\u548cASP.NET CORE ASP.NET CORE \u5728StartUp.cs\u88e1\u7684ConfigureServices\u65b9\u6cd5\u88e1\u52a0\u4e0a\u4e0a\u8ff0\u9019\u6bb5\u7a0b\u5f0f\u78bc\u3002\u8a18\u5f97\u5728AddRazorOptions\u88e1\u8981\u7528Insert\u800c\u4e0d\u8981\u7528Add\u3002Insert\u6703\u52a0\u5728\u9810\u8a2dView\u8def\u5f91\u4e4b\u524d\uff0c\u800cAdd\u6703\u52a0\u5728\u9810\u8a2dView\u8def\u5f91\u4e4b\u5f8c\u3002 \u5728Theme\u8cc7\u6599\u593e\u7522\u51facshtml\u6a94\uff0c\u63a5\u8005\u6309\u57f7\u884c\u9801\u9762\u5c31\u61c9\u6703\u512a\u5148\u7522\u51fa\u5728Theme\u8cc7\u6599\u593e\u5e95\u4e0b\u7684cshtml\u6a94\u4e86\u3002 \u57f7\u884c\u756b\u9762\u70ba ASP.NET MVC \u5efa\u7acb\u4f60\u7684Custom View Engine\u985e\u5225\u3002\u82e5\u9078\u64c7\u65b0\u7684View\u70baRazor\u985e\u578b\uff0c\u4f60\u7684\u65b0view engine class\u7e7c\u627fRazorViewEngine\u3002 \u63a5\u8005\u5728Global.asax\u88e1\uff0c\u5982ASP.NET CORE\u52a0\u4e0aView Engine\u9019\u884c\u7a0b\u5f0f\u78bc\u3002 \u9069\u7576\u4f7f\u7528Custom View Engine\u53ef\u5e6b\u6211\u5011\u5ba2\u88fd\u5316\u6574\u500b\u5c08\u6848\u7684\u67b6\u69cb\u3002\u5b78\u7fd2Custom View Engine\u4e26\u4e0d\u7b97\u96e3\u3002ASP.NET MVC\u6574\u500b\u67b6\u69cb\u4e5f\u6709\u8a31\u591a\u53ef\u4ee5\u5ba2\u88fd\u5316\u7684\u5730\u65b9\uff0c\u6709\u52a9\u65bc\u9054\u5230\u6574\u500b\u5718\u968a\u8981\u7684\u61c9\u7528\u76ee\u7684\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[38],"tags":[],"class_list":["post-561","post","type-post","status-publish","format-standard","hentry","category-pg"],"yoast_head":"\n<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n