[CLOSED] Change property of ext.net control in controller (Razor syntax)

  1. #1

    [CLOSED] Change property of ext.net control in controller (Razor syntax)

    Hi, can you tell me solution for this simple example: I have one button with id "btn3" and direct event when click on btn3. Direct event call controller method HelloWorld(). How in controller I can change properties of btn3 like Width or something else?

     @(Html.X().Button()
            .Text("Ovde") 
            .Width(200)
            .ID("btn3")
            .DirectEvents(directEvents => {
                directEvents.Click.Url = "/Test/HelloWorld";
            })
        )

    public ActionResult HelloWorld()
            {
                string script = X.Msg.Alert("DirectEvent", "Hello world!").ToScript();
                return new AjaxResult(script);
            }
    Last edited by Daniil; Apr 09, 2012 at 3:33 PM. Reason: [CLOSED]
  2. #2
    Hi,

    You can return any JavaScript from a controller action.

    Example View
    @{
         Layout = "";
    }
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>@ViewBag.Title</title>    
    </head>
    <body>    
        @Html.X().ResourceManager()
           
        @(Html.X().Button()
            .Text("Change my Width")
            .DirectEvents(directEvents => 
            {
                directEvents.Click.Url = "/Test/ChangeWidth";
                directEvents.Click.ExtraParams.Add(new Parameter("buttonId", "this.id", ParameterMode.Raw));
            })
        )
    </body>
    </html>
    Example Controller Action
    public ActionResult ChangeWidth(string buttonId)
    {
        AjaxResult r = new AjaxResult();
        string script = string.Format("Ext.getCmp('{0}').setWidth({1});", buttonId, 400);
        r.Script = script;
    
        return r;
    }
  3. #3
    In script I got this:

    Ext.getCmp(' ').setWidth(400);

    It is because in controller buttonId is null.
  4. #4
    Please demonstrate how have you configured the DirectEvent?
  5. #5
    Here is the code, the same as yours is:


    @Html.X().ResourceManager()
            
        @(Html.X().Button()
            .Text("Change my Width")
            .DirectEvents(directEvents => 
            {
                directEvents.Click.Url = "/Test/ChangeWidth";
                directEvents.Click.ExtraParams.Add(new Parameter("buttonId", "this.id", ParameterMode.Raw));
            })
        )
    And controller action:

    public ActionResult ChangeWidth(string buttonId)
            {
                AjaxResult r = new AjaxResult();
                string script = string.Format("Ext.getCmp('{0}').setWidth({1});", buttonId, 400);
                r.Script = script;
    
                return r;
            }
  6. #6
    I was unable to reproduce the problem. Please update from SVN and re-test.
  7. #7
    Update from svn helps me. Thanks! :)

Similar Threads

  1. [CLOSED] Razor syntax inside Ext Controls
    By mcfromero in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Aug 08, 2012, 7:29 PM
  2. [CLOSED] DropTarget Not working in razor syntax
    By machinableed in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 30, 2012, 11:08 AM
  3. [CLOSED] ImageCommand missing in Razor syntax
    By machinableed in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Apr 16, 2012, 12:05 PM
  4. [CLOSED] Get value from textfield in controller [Razor]
    By boris in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 10, 2012, 7:19 PM
  5. [CLOSED] Razor Syntax for ListConfig on a combobox
    By machinableed in forum 2.x Legacy Premium Help
    Replies: 6
    Last Post: Mar 27, 2012, 2:31 PM

Tags for this Thread

Posting Permissions