PDA

View Full Version : [CLOSED] [RAZOR] How to access ext.net controls from controller method



gets_gui
May 07, 2012, 4:07 PM
Hi

I'm trying to access and manipluate a control defined in a .cshtml file (below) from the controller class implementing the ButtonClick event in the controller file.

I've tried X.GetCtl which doesnt work. Is this a way of getting a reference to the controls defined on a .cshtml page from its associated controlller?

View Code:


Html.X().FormPanel()
.ID("Form")
.Title("Form")
.ButtonAlign(Alignment.Right)
.Layout("hbox")
.Items(items =>
{
items.Add(Html.X().DateField()
.ID("DateField")
.Width(120)
.DirectEvents(directEvents =>
{
directEvents.Select.Url = "/Common/DateField";
directEvents.Select.ExtraParams.Add(new Parameter()
{
Name = "Date",
Value = "item.value",
Mode = ParameterMode.Raw
});
}));

...

items.Add(Html.X().Button()
.ID("Button")
.Text("Button")
.DirectEvents(directEvents =>
{
directEvents.Click.Url = "/Common/OnButtonDirectClick";
}));


Controller Code:


public ActionResult OnButtonDirectClick(Args args)
{
...

// Get reference to the control
var ctl = X.GetCtl("DateField");

return new AjaxResult(msg);
}

Vladimir
May 07, 2012, 4:35 PM
First, Razor engine doesn't know about controls (control term is valid under WebForm engine only), there are no any instance
Second, controller action and view are not releated therefore anything in view is not accessable in an action
Third, in controller action you have to operate by input information (for example, from Request)
Fourth, you can create proxy of widget (but it is not real widget from view), it is just proxy class to load data from the client (if the widget submits it) and generate script


public AjaxResult SetValue()
{
var field = X.GetCmp<TextField>("Field1");
field.Text = field.Text + " - Append from the server";

return new AjaxResult();
}

prince-sat
Sep 12, 2012, 9:34 AM
Hi Valdimir ,
i'm trying to get selected Row from gridpanel using this function :


int selectedMember = int.Parse(MemberID);
GridPanel gridpanel = X.GetCmp<GridPanel>(GridPanelId);
MiniSiteDBEntities DBContext = new MiniSiteDBEntities();
List<CategoryMember> lstCatMem = new List<CategoryMember>();
var Query = from c in DBContext.CategoryMember
where c.MemberID == selectedMember
select c;
lstCatMem = (List<CategoryMember>)Query.ToList();
RowSelectionModel sm = gridpanel.SelectionModel.Primary as RowSelectionModel;
sm.SelectedRows.Clear();
sm.SelectedRow = new SelectedRow(lstCatMem.Count);
foreach (CategoryMember CategoryMember in lstCatMem)
{
sm.SelectedRows.Add(new SelectedRow(CategoryMember.CategoryID.ToString())) ;
}
sm.UpdateSelection();
return new AjaxResult();



but " RowSelectionModel sm = gridpanel.SelectionModel.Primary as RowSelectionModel;" return sm null

Regards.

Daniil
Sep 12, 2012, 11:48 AM
Hi @prince-sat,

X.GetCmp() works for Postback data only. A client doesn't send any info about RowSelection, so, a proxy instance doesn't contain it.

Anyway, I can't see where you "get selected row", I see you are trying to select the new rows, isn't that so?

Then I can suggest to try this.

var sm = this.GetCmp<RowSelectionModel>("selectionModelId");
// populate SelectedRows
// call UpdateSelection

prince-sat
Sep 12, 2012, 3:33 PM
Hi
In Reality I have a gridpanel with select Chekcbox and i try to check all the rows that Exists in this List "lstCatMem" which got it from Data base .
So is it the right Example Thinks .
Regards,

Daniil
Sep 13, 2012, 8:12 AM
It means that I correctly understand your requirement. Please follow my recommendation.

If the problem will persist, please start a new forum thread, because this is not tightly related to the initial topic of the current thread.