PDA

View Full Version : [CLOSED] Get value from textfield in controller [Razor]



boris
Apr 10, 2012, 3:54 PM
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.

Daniil
Apr 10, 2012, 4:57 PM
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?17742&p=77199&viewfull=1#post77199

boris
Apr 10, 2012, 5:10 PM
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);
}

Daniil
Apr 10, 2012, 7:19 PM
Well, it's not more dangerous than submitting via <form>. The same.