I want to get a value from the database and so I followed this tutorial:
Add-ServerSide-Data
but the Data (Image url ) is not showing ??
and this is my code :
1- ApiController:
[Umbraco.Web.Mvc.PluginController("Sawah")]
public class AframeApiController : UmbracoAuthorizedJsonController
{
public mainimg GetMain()
{
DataRow[] Accts =DB_Oprs.GetVRMainImg(11359);
mainimg collection = new mainimg();
foreach(DataRow r in Accts)
{
collection.versionId = r["versionId"].ToString();
collection.mediaPath = r["mediaPath"].ToString();
}
return collection;
}
public IEnumerable<mainimg> GetPinsinfo()
{
DataRow[] Accts = DB_Oprs.GetVRMainImg(11359);
IEnumerable<mainimg> collection = Accts.Cast<mainimg>();
return collection;
}
}
public class mainimg
{
public string versionId { set; get; }
public string mediaPath { set; get; }
}}
2 -added this to umbraco.resources.js :
angular.module('umbraco.resources').factory('AframeResource',
function ($q, $http, umbRequestHelper) {
// the factory object returned
return {
// this calls the ApiController we setup earlier
getMain: function () {
return umbRequestHelper.resourcePromise(
$http.get("backoffice/Sawah/AframeApi/GetMain"),
"Failed to retrieve GetMain inmage");
},
getPins: function () {
return umbRequestHelper.resourcePromise(
$http.get("backoffice/Sawah/AframeApi/GetPinsinfo"),
"Failed to retrieve GetPins data");
}
};
}
);
Are you able to provide a bit more on what you are trying to achieve?
For example if you have the ID of the media stored in umbraco then you could grab the path using something like this:
string mediaUrl = "";
//get media using id
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var media = umbracoHelper.Media(id);
mediaUrl = media.url;
In regards to the code you've provided, are you seeing the versionID pull through as that's what is stated in your html?
Also have you debugged the code and is mediaPath being returned ok?
creating Resource to get a database value
Hi,
I want to get a value from the database and so I followed this tutorial: Add-ServerSide-Data
but the Data (Image url ) is not showing ?? and this is my code :
1- ApiController:
2 -added this to umbraco.resources.js :
3- this is the angular controller code
4- this is the html page :
5- this is the package.manifest
can anyone help me ??
Hi,
Are you able to provide a bit more on what you are trying to achieve?
For example if you have the ID of the media stored in umbraco then you could grab the path using something like this:
In regards to the code you've provided, are you seeing the versionID pull through as that's what is stated in your html?
Also have you debugged the code and is mediaPath being returned ok?
Kind Regards, Lewis
Hi Lewis,
I want to create a custom property editor that shows data from the current content page...
and yes I debugged the code and the controller is retrieving the imagepath. but in the HTML view, nothing is showing....
thanks.
Hi again,
Just trying to narrow down where the problem may lie. Are you able to debug and see what response.data returns? Does that have the expected values?
Kind Regards, Lewis
is working on a reply...