mirror of
https://github.com/rudollee/LearningMVC.git
synced 2026-08-11 16:32:55 +00:00
Ch. 20 Views
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Views.Infrastructure
|
||||
{
|
||||
public class DebugDataView : IView
|
||||
{
|
||||
public void Render(ViewContext viewContext, TextWriter writer)
|
||||
{
|
||||
Write(writer, "---Routing Data---");
|
||||
foreach (string key in viewContext.RouteData.Values.Keys)
|
||||
{
|
||||
Write(writer, "Key: {0}, Value: {1}", key, viewContext.RouteData.Values[key]);
|
||||
}
|
||||
|
||||
Write(writer, "---View Data---");
|
||||
foreach (string key in viewContext.ViewData.Keys)
|
||||
{
|
||||
Write(writer, "Key: {0}, Value: {1}", key, viewContext.ViewData[key]);
|
||||
}
|
||||
}
|
||||
|
||||
private void Write(TextWriter writer, string template, params object[] values)
|
||||
{
|
||||
writer.Write(string.Format(template, values) + "<p/>");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Views.Infrastructure
|
||||
{
|
||||
public class DebugDataViewEngine : IViewEngine
|
||||
{
|
||||
public ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
|
||||
{
|
||||
if (viewName == "DebugData")
|
||||
{
|
||||
return new ViewEngineResult(new DebugDataView(), this);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ViewEngineResult(new string[] { "no view (Debug Data View Engine)" });
|
||||
}
|
||||
}
|
||||
|
||||
public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache)
|
||||
{
|
||||
return new ViewEngineResult(new string[] { "No view (Debug Data View Engine)" });
|
||||
}
|
||||
|
||||
public void ReleaseView(ControllerContext controllerContext, IView view)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user