This project is read-only.

Integration with ASP.NET MVC

Setting up View engine

To use Landscape as as MVC view engine, download the last release, reference Landscape.dll and Landscape.MVC.dll into your project and add this snippet into your Global.asax.

protected void Application_Start() {
  //ViewEngines.Engines.Clear();
  ViewEngines.Engines.Add(new Landscape.MVC.XSLTViewEngine());
}

You don't even need to worry about location formats (translated: explain to asp.net where to find view) since Landscape automatically translates its Template folder sources into ASP.NET locations.

If you want to use Landscape as your only view engine, just decomment the

//ViewEngines.Engines.Clear();

Once you have done this, you need to create a configuration file for Landscape. Please refer to the Configuration for more information.

Using views

To render a Landscape MVC view, you may supply a valid datasource as the ViewModel and a dictionary of view parameters using the ViewData dictionary:

If you don't supply a datasource, Landscape will create an empty XmlDocument with a <root/> node.

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
	    // here we define the datasource used for XSLT transformation
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.Load(Server.MapPath("~/Website.xml"));
	    // now we store it into the viewmodel
            ViewData.Model = doc;

	    // optionally, we supply parameters through ViewData
            ViewData["loginUrl"] = Url.Action("login", "auth");
            return View();
        }

    }

Last edited Oct 31, 2011 at 12:04 AM by Kunyo, version 9

Comments

No comments yet.