Hosting the XForms Engine in ASP.NET

PRELIMINARY INFORMATION - SUBJECT TO CHANGE

Release 2.1 - ...

The XFormsAspNetIntegrator class can be used from ASP.NET WebPages and ASP.NET MVC to host the XForms Engine.

For example, in MVC, use the following code:

  CopyCode image Copy Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using Smartsite.XForms.AspNet;
namespace MvcTestApp.Controllers {
    [HandleError]
    public class FormController : Controller {
       public ActionResult Show(string form) {
            if (!string.IsNullOrEmpty(form)) {
                Uri formFile = new Uri(HttpContext.Request.Url, "/assets/" + form);
                XFormsAspNetIntegrator xi = new XFormsAspNetIntegrator(this.HttpContext.ApplicationInstance.Context, formFile);
                ViewData["FormHtml"] = xi.Html;
                foreach (string item in xi.PropertyBag){
                    ViewData[item] = xi.PropertyBag[item];
                }
            }
            return View();
        }
    }
}

The following Razr view can then output the result:

HTML CopyCode image Copy Code
@{
    ViewBag.Title = "Show";
}
 
@section LocalScript {
    <script type="text/javascript">
        $(function () {
            @Html.Raw(ViewBag.onloadscript)
        });
    </script>
}
<h2>Show</h2>
<div>
    @Html.Raw(ViewBag.FormHtml)
</div>