Direct Events with Razor

  1. #1

    Direct Events with Razor

    Hi All,

    The original working code looked like this:

    <ext:Button ID="btnDelete" runat="server" Text="Delete" Icon="Cross"> 
                                        <DirectEvents> 
                                            <Click 
                                                Url="/Data/DeleteBankAccount" 
                                                CleanRequest="true" 
                                                Method="POST" 
                                                Failure="Ext.Msg.show({title:'Delete Error',msg: result.errorMessage,buttons: Ext.Msg.OK,icon: Ext.Msg.ERROR});" 
                                                Success="txtBankAccounts.lastQuery=null; bankAccountChanged = true;#{BankAccountPager}.doLoad(Math.max(0, #{BankAccountPager}.cursor-1));"> 
                                                <Confirmation ConfirmRequest="true" Title="Alert" Message="Delete Record?" /> 
                                                <ExtraParams> 
                                                    <ext:Parameter Name="accountID" Value="#{dsBankAccountInstance}.getAt(0).AccountID" Mode="Raw" /> 
                                                </ExtraParams> 
                                            </Click> 
                                        </DirectEvents> 
                                    </ext:Button>
    Problem:
    In razor, I am attempting to package it up like this:
                                   items.Add(Html.X().Button().ID("btnDelete").Text("Delete").Icon(Icon.Cross) 
                                        .DirectEvents(directEvents => { 
                                            <Click 
                                                .Url="/Data/DeleteBankAccount" 
                                                CleanRequest=true 
                                                Method="POST" 
                                                Failure="Ext.Msg.show({title:'Delete Error',msg: result.errorMessage,buttons: Ext.Msg.OK,icon: Ext.Msg.ERROR});" 
                                                Success="txtBankAccounts.lastQuery=null; bankAccountChanged = true;#{BankAccountPager}.doLoad(Math.max(0, #{BankAccountPager}.cursor-1));"> 
                                                <Confirmation ConfirmRequest=true Title("Alert" Message="Delete Record?)); 
                                                .ExtraParams(extraParams => { 
                                                    parameters.Add(Html.X().Parameter().Name("accountID").Value("#{dsBankAccountInstance}.getAt(0).AccountID").Mode(ParameterMode.Raw));
    
                                               }) 
                                            </Click> 
                                        }) 
                                    );
    How do I package up the <Click handler. Intelllisense doesn't see a directEvents.Click property. Along with this, how will I package up the parameters. The example that was given in the Forum was simple. It just had a Url. How about the rest of the Click parameters. Do I treat each one as an extra parameter?
    Last edited by Daniil; Aug 06, 2012 at 9:40 AM. Reason: Please use [CODE] tags
  2. #2
    Hi,

    This ASPX markup syntax is not available under Razor.

    Please look at the example.
    http://forums.ext.net/showthread.php...ll=1#post78313
  3. #3

    Direct Event using Razor

    Quote Originally Posted by Daniil View Post
    Hi,

    This ASPX markup syntax is not available under Razor.

    Please look at the example.
    http://forums.ext.net/showthread.php...ll=1#post78313
    You misunderstand my question. I know that the following is not correct.

       
     .DirectEvents(directEvents => 
    {          
          <Click             
               .Url="/Data/DeleteBankAccount"            
               CleanRequest=true             
               Method="POST"             
               Failure="Ext.Msg.show({title:'Delete Error',msg: result.errorMessage,buttons: Ext.Msg.OK,icon: Ext.Msg.ERROR});"                
              Success="txtBankAccounts.lastQuery=null; bankAccountChanged = true;#{BankAccountPager}.doLoad(Math.max(0, #  
              {BankAccountPager}.cursor-1));">              
              <Confirmation ConfirmRequest=true Title("Alert" Message="Delete Record?));              
              .ExtraParams(extraParams =>  {                   
                      parameters.Add(Html.X().Parameter().Name("accountID").Value("#{dsBankAccountInstance}.getAt(0).AccountID").Mode  
                      (ParameterMode.Raw));             
              })          
          </Click> 
    }
    The examples that are provided in the forum would look something like this:
    .DirectEvents(directEvents => 
    {
          directEvents.Click.Url="/Data/DeleteBankAccount"
          directEvents.Click.CleanRequest="true";
          directEvents.Click.Post="POST"
    As I indicated above, I don't know how to package the content between the <Click></Click> tags and its attributes. All the samples in the Forum just have the directEvents.Click.Url type of statement. How do I package the attributes such as CleanRequest, Post, Failure etc. using Razor? Also how I deal with the Confirmation tag using the razor syntax? I have converted a tremendous amount of code to the razor engine but I am having trouble with this simple multi-line Click Event. Many of your samples have this type of aspx structure.
    Last edited by Daniil; Aug 15, 2012 at 10:40 AM.
  4. #4
    Hope this examples helps.

    Example View
    <!DOCTYPE html>
    
    <html>
    <head>
        <title>Ext.Net.MVC v2 Example</title>    
    </head>
    <body>
        @Html.X().ResourceManager()
    
        @(Html.X().Button()
            .Text("Click me")
            .DirectEvents(de =>
                {
                    de.Click.Url = "/Razor/ClickMeHandler";
                    de.Click.CleanRequest = true;
                    de.Click.Method = HttpMethod.POST;
                    de.Click.Confirmation.ConfirmRequest = true;
                    de.Click.Confirmation.Title = "Confirmation title";
                    de.Click.ExtraParams.Add(new Parameter("test", "Hello!", ParameterMode.Value));
                }
            )
        )
    </body>
    </html>
    Example Action
    public ActionResult ClickMeHandler(string msg)
    {
        X.Msg.Alert("Controller says:", "msg").Show();
        AjaxResult r = new AjaxResult();
        return r;
    }

Similar Threads

  1. Dynamic UserControl + Direct Events
    By Zdenek in forum 2.x Help
    Replies: 4
    Last Post: Jul 22, 2012, 5:51 PM
  2. [CLOSED] [Razor] Row expander + multiple direct events
    By machinableed in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Jun 21, 2012, 3:39 AM
  3. Direct Events dynamic Url
    By Tallmaris in forum 1.x Help
    Replies: 1
    Last Post: Aug 18, 2011, 1:26 PM
  4. Calendar - EventEditForm - Direct Events
    By vwagoner in forum 1.x Help
    Replies: 4
    Last Post: Jun 17, 2011, 5:27 PM
  5. [CLOSED] Direct events in user control
    By tiramisu in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Dec 13, 2010, 11:34 AM

Posting Permissions