Need the Controller ID in MVC for a Custom Form Widget

Posted by Community Admin on 04-Aug-2018 19:19

Need the Controller ID in MVC for a Custom Form Widget

All Replies

Posted by Community Admin on 06-Jul-2016 00:00

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

Posted by Community Admin on 06-Jul-2016 00:00

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

Posted by Community Admin on 06-Jul-2016 00:00

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. 

Posted by Community Admin on 07-Jul-2016 00:00

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?

This thread is closed