ASP. NET Vnext Implementation iview

Source: Internet
Author: User

Overview

The iview definition is simple to render a view based on the view context and the TextWriter object.

Realize

Implement Iviewengine

   Public classTestviewengine:iviewengine { PublicViewengineresult Findpartialview (Actioncontext context,stringpartialviewname) {            //if ViewName equals Partial-test-view, use Testpartialview            if(string. Equals (Partialviewname,"Partial-test-view", StringComparison.Ordinal)) {                returnViewengineresult.found (Partialviewname,NewTestpartialview ()); }            returnViewengineresult.notfound (Partialviewname,New[] {partialviewname}); }         PublicViewengineresult Findview (Actioncontext context,stringviewName) {            //if ViewName equals Test-view, use TestView            if(string. Equals (ViewName,"Test-view"))            {                returnViewengineresult.found (ViewName,NewTestView ()); }            returnViewengineresult.notfound (ViewName,New[] {viewName}); }    }

Implement iview

 public  class   Testpartialview:iview { public  str ing  Path {get ; set          public  async   Task Renderasync (ViewContext context) { //  There is no view, the world output browser  await  context. Writer.writelineasync (  " ); }    }
 public  class   Testview:iview { public  string Path {get ; set          public  async   Task Renderasync (ViewContext context) { await  cont Ext. Writer.writelineasync (  Span style= "color: #800000;" > " +context. Viewbag.images +  />   " ); }    }

controller

 public  class   Homecontroller:controller { public   ViewResult Index () { return          View ();             public   ViewResult TestView () {viewbag.images  =  /images/asp-net-                   Banners-01.png   ;  return  View ( " test-view   ); }         }

Start class

  Public classStartup { Public voidconfigureservices (iservicecollection services) {services. Addmvc (). CONFIGUREMVC (Options=                {                    //join the View engineOptions. Viewengines.insert (0,typeof(Testviewengine));            }); }         Public voidConfigure (Iapplicationbuilder app) {app. USEMVC (Routes={routes. MapRoute (Name:"default", Template:"{controller=home}/{action=index}/{id?}");        }); }    }

Run

Limited expression Here is an article about: http://www.cnblogs.com/artech/archive/2012/08/22/view-engine-01.html

SOURCE Download Http://pan.baidu.com/s/1qWOcZ0K

ASP. NET Vnext Implementation iview

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.