{"id":548,"date":"2021-06-16T23:18:25","date_gmt":"2021-06-16T23:18:25","guid":{"rendered":"https:\/\/turtleflyblog.com\/?p=548"},"modified":"2022-02-28T09:20:51","modified_gmt":"2022-02-28T09:20:51","slug":"custom-view-engine","status":"publish","type":"post","link":"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/","title":{"rendered":"Custom View Engine"},"content":{"rendered":"\n

In ASP.NET MVC, every controller can have multiple Action functions and each Action\u2019s result is likely to be View. View Engine does the view render task. We will look the whole View Result Execution Process first.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

The diagram above shows the framework will choose the default View path to run. If it does not find View in the default path, then it will find View in the second default path which set.<\/p>\n\n\n\n

When the project architecture needs to adjust, View in some conditions may also have to change its default path to the new path based on the new project architecture needs. We can achieve this by Customizing View Engine.<\/strong> This article will introduce how to customize view engine in both ASP.NET MVC and ASP.NET CORE framework.<\/p>\n\n\n\n

ASP.NET CORE<\/strong><\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Add the above code in ConfigureServices method which is In StartUp.cs. Remember in AddRazorOptions method we have to use Insert <\/strong>rather than Add <\/strong>if you want your new View path has higher priority than the default path in selection. Use Insert<\/strong> will set your path before the default paths. However if you use Add <\/strong>method, your path will add after the default ones.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n
\"\"<\/figure>\n\n\n\n

Add your cshtml file in the Theme folder, then you shall see the webpage below after you execute the process.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

ASP.NET MVC<\/strong><\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Create your Custom View Engine class. If you want your view to be razor type, then let your new view engine class inherit RazorViewEngine class.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Then add the code above in Global.asax class just like the one you did in ASP.NET CORE.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Appropriate use custom view engine help to build the project architecture that the develop teams want. Custom View Engine is not a hard topic. Asp.NET MVC provides many mechanisms for develops to customize the framework structure they want, this helps to achieve the team\u2019s goal and application.<\/p>\n","protected":false},"excerpt":{"rendered":"

In ASP.NET MVC, every controller can have multiple Action functions and each Action\u2019s result is likely to be View. View Engine does the view render task. We will look the whole View Result Execution Process first. The diagram above shows the framework will choose the default View path to run. If it does not find […]<\/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":[33],"tags":[],"class_list":["post-548","post","type-post","status-publish","format-standard","hentry","category-programming-2"],"yoast_head":"\nCustom View Engine - Who said turtle cannot fly<\/title>\n<meta name=\"description\" content=\"In ASP.NET MVC, every controller can have multiple Action functions and each Action\u2019s result is likely to be View. View Engine does the view render task. We will look the whole View Result Execution Process first.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Custom View Engine - Who said turtle cannot fly\" \/>\n<meta property=\"og:description\" content=\"In ASP.NET MVC, every controller can have multiple Action functions and each Action\u2019s result is likely to be View. View Engine does the view render task. We will look the whole View Result Execution Process first.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/\" \/>\n<meta property=\"og:site_name\" content=\"Who said turtle cannot fly\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-16T23:18:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-28T09:20:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/turtleflyblog.com\/wp-content\/uploads\/2021\/06\/1-2.png\" \/>\n<meta name=\"author\" content=\"Joseph\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Joseph\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/\",\"url\":\"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/\",\"name\":\"Custom View Engine - Who said turtle cannot fly\",\"isPartOf\":{\"@id\":\"https:\/\/turtleflyblog.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/turtleflyblog.com\/wp-content\/uploads\/2021\/06\/1-2.png\",\"datePublished\":\"2021-06-16T23:18:25+00:00\",\"dateModified\":\"2022-02-28T09:20:51+00:00\",\"author\":{\"@id\":\"https:\/\/turtleflyblog.com\/#\/schema\/person\/130c2e1bdce4a8ba27bfe14c65988172\"},\"description\":\"In ASP.NET MVC, every controller can have multiple Action functions and each Action\u2019s result is likely to be View. View Engine does the view render task. We will look the whole View Result Execution Process first.\",\"breadcrumb\":{\"@id\":\"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/#breadcrumb\"},\"inLanguage\":\"en-AU\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-AU\",\"@id\":\"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/turtleflyblog.com\/wp-content\/uploads\/2021\/06\/1-2.png?fit=522%2C417&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/turtleflyblog.com\/wp-content\/uploads\/2021\/06\/1-2.png?fit=522%2C417&ssl=1\",\"width\":522,\"height\":417},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/turtleflyblog.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Custom View Engine\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/turtleflyblog.com\/#website\",\"url\":\"https:\/\/turtleflyblog.com\/\",\"name\":\"Who said turtle cannot fly\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/turtleflyblog.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-AU\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/turtleflyblog.com\/#\/schema\/person\/130c2e1bdce4a8ba27bfe14c65988172\",\"name\":\"Joseph\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-AU\",\"@id\":\"https:\/\/turtleflyblog.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/539caa7bc4af75cd4ab82fc8d51935da?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/539caa7bc4af75cd4ab82fc8d51935da?s=96&d=mm&r=g\",\"caption\":\"Joseph\"},\"sameAs\":[\"https:\/\/turtleflyblog.com\/\/\"],\"url\":\"https:\/\/turtleflyblog.com\/author\/joseph\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Custom View Engine - Who said turtle cannot fly","description":"In ASP.NET MVC, every controller can have multiple Action functions and each Action\u2019s result is likely to be View. View Engine does the view render task. We will look the whole View Result Execution Process first.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/","og_locale":"en_US","og_type":"article","og_title":"Custom View Engine - Who said turtle cannot fly","og_description":"In ASP.NET MVC, every controller can have multiple Action functions and each Action\u2019s result is likely to be View. View Engine does the view render task. We will look the whole View Result Execution Process first.","og_url":"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/","og_site_name":"Who said turtle cannot fly","article_published_time":"2021-06-16T23:18:25+00:00","article_modified_time":"2022-02-28T09:20:51+00:00","og_image":[{"url":"https:\/\/turtleflyblog.com\/wp-content\/uploads\/2021\/06\/1-2.png"}],"author":"Joseph","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Joseph","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/","url":"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/","name":"Custom View Engine - Who said turtle cannot fly","isPartOf":{"@id":"https:\/\/turtleflyblog.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/#primaryimage"},"image":{"@id":"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/#primaryimage"},"thumbnailUrl":"https:\/\/turtleflyblog.com\/wp-content\/uploads\/2021\/06\/1-2.png","datePublished":"2021-06-16T23:18:25+00:00","dateModified":"2022-02-28T09:20:51+00:00","author":{"@id":"https:\/\/turtleflyblog.com\/#\/schema\/person\/130c2e1bdce4a8ba27bfe14c65988172"},"description":"In ASP.NET MVC, every controller can have multiple Action functions and each Action\u2019s result is likely to be View. View Engine does the view render task. We will look the whole View Result Execution Process first.","breadcrumb":{"@id":"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/#breadcrumb"},"inLanguage":"en-AU","potentialAction":[{"@type":"ReadAction","target":["https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/"]}]},{"@type":"ImageObject","inLanguage":"en-AU","@id":"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/#primaryimage","url":"https:\/\/i0.wp.com\/turtleflyblog.com\/wp-content\/uploads\/2021\/06\/1-2.png?fit=522%2C417&ssl=1","contentUrl":"https:\/\/i0.wp.com\/turtleflyblog.com\/wp-content\/uploads\/2021\/06\/1-2.png?fit=522%2C417&ssl=1","width":522,"height":417},{"@type":"BreadcrumbList","@id":"https:\/\/turtleflyblog.com\/en\/2021\/06\/16\/custom-view-engine\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/turtleflyblog.com\/en\/"},{"@type":"ListItem","position":2,"name":"Custom View Engine"}]},{"@type":"WebSite","@id":"https:\/\/turtleflyblog.com\/#website","url":"https:\/\/turtleflyblog.com\/","name":"Who said turtle cannot fly","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/turtleflyblog.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-AU"},{"@type":"Person","@id":"https:\/\/turtleflyblog.com\/#\/schema\/person\/130c2e1bdce4a8ba27bfe14c65988172","name":"Joseph","image":{"@type":"ImageObject","inLanguage":"en-AU","@id":"https:\/\/turtleflyblog.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/539caa7bc4af75cd4ab82fc8d51935da?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/539caa7bc4af75cd4ab82fc8d51935da?s=96&d=mm&r=g","caption":"Joseph"},"sameAs":["https:\/\/turtleflyblog.com\/\/"],"url":"https:\/\/turtleflyblog.com\/author\/joseph\/"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/posts\/548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/comments?post=548"}],"version-history":[{"count":1,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/posts\/548\/revisions"}],"predecessor-version":[{"id":656,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/posts\/548\/revisions\/656"}],"wp:attachment":[{"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/media?parent=548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/categories?post=548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/tags?post=548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}