[CLOSED] Get value from textfield in controller [Razor]

  1. #1

    [CLOSED] Get value from textfield in controller [Razor]

    When using direct click on button i can get value form one textfield in controller, but when use direct click in button on window value of textbox is null.

    This is a textfield:

    @Html.X().TextField().ID("tfID").FieldLabel("Labela 23").Text("Some text ...")
    This example works:

    @(Html.X().Button()
            .ID("btnID2")
            .Text("Direct event 2")
            .DirectEvents(directEvents => 
            {
                directEvents.Click.Url = "/Account/TestMethod";
            })
        )
    and controller:

    public ActionResult TestMethod(string tfID) 
            {
                AjaxResult r = new AjaxResult();
                r.Script = X.Msg.Alert("", "Vrednost: " + tfID).ToScript();
                return r;
            }

    But in this example where I only use Window it is not work:

    @(Html.X().Window().ID("WindowLogIn")
            .Layout(LayoutType.Anchor)
            .Width(300)
            .Height(150)
            .Title("Test")
                .Items(item =>
                {
                    item.Add(Html.X().Button().ID("ButtonPrijava").Text("Prijavi me").DirectEvents(directEvents => { directEvents.Click.Url = "/Account/TestMethod"; })); 
                })
    
        )

    For both examples I put razor code in BeginForm

    @using (Html.BeginForm())
    {
    }
    Can you help me to handle this data from textbox in controller.
    Last edited by Daniil; Apr 16, 2012 at 11:53 AM. Reason: [CLOSED]
  2. #2
    Hi,

    I would suggest to send it as an extra parameter of DirectEvent.

    If it's not an option, please set up an id for Form and set ResourceManager FormID to that id.

    The second example in this post:
    http://forums.ext.net/showthread.php...ll=1#post77199
  3. #3
    Is option with DirectEvent safe for login form?

    For example if I use this for login form:

        @Html.X().TextField().Text("password").ID("tfID4").InputType(Ext.Net.InputType.Password)
    
    
        @(Html.X().Button()
            .Text("Zdravo")
            .DirectEvents(directEvents => {
                directEvents.Click.Url = "/Account/Zdravo";
                directEvents.Click.ExtraParams.Add(new Parameter("p1", "some username", ParameterMode.Value));
                directEvents.Click.ExtraParams.Add(new Parameter { Name = "p2", Value = "Ext.getCmp('tfID4').getValue()", Mode = ParameterMode.Value });
                
            })
        )

    and controller:

           public ActionResult Zdravo(string p1, string p2, string tfID4)
            {
                string script = X.Msg.Alert("DirectEvent", "P1 = " + p1 + " P2 = " + p2 + " Tekst polje = " + tfID4).ToScript();
                return new AjaxResult(script);
            }
  4. #4
    Well, it's not more dangerous than submitting via <form>. The same.

Similar Threads

  1. Replies: 5
    Last Post: Sep 13, 2012, 8:12 AM
  2. Replies: 8
    Last Post: May 18, 2012, 9:43 AM
  3. [Razor] Populating form values from controller
    By machinableed in forum 2.x Premium Help
    Replies: 2
    Last Post: May 07, 2012, 10:42 AM
  4. Replies: 6
    Last Post: Apr 09, 2012, 3:33 PM
  5. [CLOSED] How to access/reload store in razor views/controller
    By machinableed in forum 2.x Premium Help
    Replies: 5
    Last Post: Apr 02, 2012, 1:38 PM

Tags for this Thread

Posting Permissions