[CLOSED] [RAZOR] How to access ext.net controls from controller method

  1. #1

    [CLOSED] [RAZOR] How to access ext.net controls from controller method

    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);
            }
    Last edited by Daniil; May 11, 2012 at 4:32 PM. Reason: [CLOSED]
  2. #2
    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();
            }
    Last edited by Daniil; May 08, 2012 at 9:30 AM. Reason: Code tags
  3. #3

    RowSelection Modal Razor

    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.
  4. #4
    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
  5. #5

    Explain

    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,
  6. #6
    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.

Similar Threads

  1. [Razor] Populating form values from controller
    By machinableed in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: May 07, 2012, 10:42 AM
  2. [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
  3. Replies: 1
    Last Post: Apr 09, 2012, 1:07 PM
  4. [CLOSED] How to access/reload store in razor views/controller
    By machinableed in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Apr 02, 2012, 1:38 PM
  5. Replies: 1
    Last Post: Jul 25, 2011, 9:59 AM

Tags for this Thread

Posting Permissions