View Full Version : [CLOSED] Change property of ext.net control in controller (Razor syntax)
boris
Apr 06, 2012, 10:06 AM
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);
}
Daniil
Apr 06, 2012, 10:56 AM
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;
}
boris
Apr 06, 2012, 4:24 PM
In script I got this:
Ext.getCmp(' ').setWidth(400);
It is because in controller buttonId is null.
Daniil
Apr 06, 2012, 4:31 PM
Please demonstrate how have you configured the DirectEvent?
boris
Apr 09, 2012, 3:10 PM
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;
}
Daniil
Apr 09, 2012, 3:57 PM
I was unable to reproduce the problem. Please update from SVN and re-test.
boris
Apr 09, 2012, 4:33 PM
Update from svn helps me. Thanks! :)
Powered by vBulletin® Version 4.2.3 Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.