Book Image

Ext.NET Web Application Development

By : Anup K Shah
Book Image

Ext.NET Web Application Development

By: Anup K Shah

Overview of this book

To build a rich internet application, you need to integrate a powerful client side JavaScript framework with a server side framework. Ext.NET achieves this by integrating Sencha's Ext JS framework with the power of ASP.NET. The result ñ a sophisticated framework offering a vast array of controls, layout, and powerful AJAX and server bindings, which can be used to build rich, highly usable web applications. "Ext.NET Web Application Development" shows you how to build rich applications using Ext.NET. Examples guide you through Ext.NET's various components using both ASP.NET Web Forms and MVC examples. You will also see how Ext.NET handles data binding and server integration. You will also learn how to create reusable components and put them together in great looking applications. This book guides you through the various Ext.NET components and capabilities to enable you to create highly usable Ext.NET components and web applications. You will learn about various UI components and numerous layout options through examples. You will see how the AJAX architecture enables you to create powerful data-oriented applications easily. This book will also teach you how to create reusable custom components to suit your needs. "Ext.NET Web Application Development" shows you how to create rich and usable applications using Ext.NET through numerous examples.
Table of Contents (17 chapters)
Ext.NET Web Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
8
Trees and Tabs with Ext.NET
Index

A walkthrough – creating a simple ASP.NET MVC Project with Razor and Ext.NET enabled


Ext.NET also supports ASP.NET MVC with both the default view template engine, as well as the popular Razor engine. Although the majority of this book will mostly show examples using ASP.NET Web Forms, there will be some examples showing MVC and Razor usage.

Creating an MVC project and enabling Ext.NET

To get MVC support, there is a similar NuGet package, called Ext.Net.MVC. So, you can follow the earlier steps, but instead do the following:

  1. Create a new ASP.NET MVC 3 Web Application project.

  2. Use the following NuGet command:

    Install-Package Ext.NET.MVC
    

The changes will be the same as before. Web.config will be updated for you as needed, and Global.asax will have an additional route registered to handle Ext.NET resources.

Tip

The following Ext.NET forum post is worth looking at to see how to manually apply the configuration changes to an existing project (because you can always use ASP.NET Web Forms and ASP.NET MVC in one project if you wish):

http://forums.ext.net/showthread.php?16920

The sample Ext.NET page using MVC and Razor

To get a feel of how Ext.NET looks in MVC/Razor, here is a similar example as earlier, but using the MVC/Razor syntax. First, the View:

<!DOCTYPE html>
<html>
<head>
    <title>Ext.NET Example</title>
</head>
<body>    
    @Html.X().ResourceManager().Theme(Theme.Gray)

    @(Html.X().Window()
        .Title("Welcome to Ext.NET 2.1")
        .Height(215)
        .Width(350)
        .Layout(LayoutType.Fit)
        .Items(Html.X().FormPanel()
            .Layout(LayoutType.Anchor)
            .DefaultAnchor("100%")
            .Border(false)
            .BodyPadding(5)
            .Items(Html.X().TextArea()
                .ID("message")
                .EmptyText(">> Enter a Message Here <<")
                .FieldLabel("Text Message")
                .Height(85)
            )
            .Buttons(
                Html.X().Button()
                    .Text("Submit")
                    .Icon(Icon.Accept)
                    .DirectClickAction("Notify", "ExtNET")
            )
        )
    )
</body>
</html>

And next, the Controller:

using System.Web.Mvc;
using Ext.Net;
using Ext.Net.MVC;
using Controller = System.Web.Mvc.Controller;

namespace ExtNet2Mvc.Controllers
{
    public class DirectEventExampleController : Controller
    {  
      //
      // GET: /DirectEventExample/
      public ActionResult Index()
      {
          return View();
      }
      //
      // GET: /DirectEventExample/Notify/
      public ActionResult Notify(string message)
      {
          var config = new NotificationConfig
          {
              Icon = Icon.Accept,
              Title = "Working",
              Html = message
          };

          X.Msg.Notify(config).Show();

          return this.Direct();
       }
    }
}

The code does the same thing as the ASP.NET Web Forms example, earlier. We have defined two actions in the same controller. The Index, or default action when browsing /DirectEventExample/ will simply return the View. The View creates the same components as before, but using Razor syntax and Ext.NET's MVC helper methods.

The button's Click DirectEvent is slightly different; the associated controller action, Notify, takes a string parameter. To set that parameter, the Click DirectEvent adds it as an extra parameter getting the value via a small bit of client-side JavaScript code (which gets the value of the client-side representation of the text area).

To handle the event on the server side, the Notify action creates an Ext.NET Notification object and shows it. The Direct() method generates a DirectResult which is a subclass of ActionResult. It is a class created by Ext.NET and handles the script generation so that the Notification object appears on the user's browser.

These techniques will, of course, be expanded upon in this book, so don't worry about the inner workings in too much detail for now! The key points to take away for MVC Razor is that it generally follows the standard ASP.NET MVC Razor patterns and Ext.NET components come with their own helper methods to help configure the controls as needed. There will be additional features specific to MVC that Ext.NET is building even as this book goes to print so there will be more capabilities to expect that cannot be covered in this book, including Data Annotations support, Model Binding support, specialized Ext.NET action results, and more.