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