+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Need the Controller ID in MVC for a Custom Form Widget

Need the Controller ID in MVC for a Custom Form Widget

4 posts, 0 answered
  1. Yuri
    Yuri avatar
    3 posts
    Registered:
    19 May 2015
    06 Jul
    Link to this post

    Hi,

     

    I am developing a custom form widget with a CRUD datasource.

    I was using url actions to communicate with the server side:

          @Url.Action("Editing_Read")

    and also:

        @Url.Action("Controller_Editing_", "ControllerName")

    Worked great until I put 2 of the same widgets on a page, so the second widget would hit the ActionResult in the first controller...

     

    So I have decided to try WebServices. I have implemented the wireframe for the webservice with hard coded data and it works.

    But in order to continue I need to know my specific controller ID  or FormControl ID so that I can send it along with the request to the WebService. I know each controller on a page or form has a Guid. But no API to access it.

     

    The Question: How do I find the Form Controller (MVC Widget) ID from the Controller

  2. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    06 Jul in reply to Yuri
    Link to this post

    Hi Yuri. Can you please check this thread. http://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/get-custom-control-id-from-control-s-code-behind

    In this thread described how to get widget ID

  3. Yuri
    Yuri avatar
    3 posts
    Registered:
    19 May 2015
    06 Jul
    Link to this post

    Thanks for the fast reply,

     

    Unfortunately this won't work for me because I cannot rely on the Caption or Title:

    var uControls = tempPage.Controls.Where(c => c.Caption =="WebUserControl1").FirstOrDefault();

    I may have two controllers with same caption and same types.

     

     

    I am trying to get the ID of the Controller while I am anywhere  inside the Controller itself. In a perfect world I would do this:

    Guid id = this.id;  /* "this" is the instance of this Controller */

     

    So If I am in this controller how do I query for this.id? Maybe without using the PageManager to get the Form, then to look for this controller. I am here at this anyway I just need to query for the id. 

  4. Yuri
    Yuri avatar
    3 posts
    Registered:
    19 May 2015
    07 Jul in reply to Yuri
    Link to this post

    Can you take a look at this again in more detail?

    Or explain why it is not possible to get a controller ID from within the controller itself?

4 posts, 0 answered