I wrote following code. Not sure whether it is correct way or not.
This code works good under Forms -> Prevalue Sources
It is showing all values from web api
3.Then I am able to add dropdown on form also. No error
When I am try to add form on the page. I am getting following exception
Any idea, how to solve this issue. I am using Clean Starter Kit with umbraco 8
public class ExperimentDataSource : FieldPreValueSourceType
{
[Setting("Url", Description = "Enter the url to post to", View = "TextField")]
public string Url
{
get;
set;
}
[Setting("Value to Display", Description = "Enter the url to post to", View = "TextField")]
public string ListOfValues
{
get;
set;
}
public ExperimentDataSource()
{
Id = new Guid("74557737-FE48-4911-9FC2-952315B85B63");
Name = "Read From Web Service";
Description = "This is experiement";
}
public override List<PreValue> GetPreValues(Field field, Form form)
{
List<PreValue> result = new List<PreValue>();
using (WebClient http = new WebClient())
{
http.Headers.Add(HttpRequestHeader.ContentType, "application/json");
try
{
var json = new WebClient().DownloadString(Url);
dynamic dynJson = JsonConvert.DeserializeObject(json);
foreach (var item in dynJson)
{
PreValue pv = new PreValue();
pv.Id = item.ID;
pv.Value = item[ListOfValues].ToString();
result.Add(pv);
}
}
catch (Exception ex)
{
string err = String.Format("There was a problem sending the Record with unique id '{0}' from the Form '{1}' with id '{2}' to the URL Endpoint '{3}' with the method 'POST'");
}
}
return result;
}
public override List<Exception> ValidateSettings()
{
List<Exception> exceptions = new List<Exception>();
if (Url.Trim().Length < 1)
{
exceptions.Add(new Exception("Url value must be supplied."));
}
return exceptions;
}
}
exception
System.Web.HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Umbraco.Forms.Web.Models.FormViewModel.<>c.
FieldPreValueSourceType with custom web api service
I am trying to develop custom prevalue source type which will read data from web service or web api.
Is there any good example available as reference ?
Hi
I wrote following code. Not sure whether it is correct way or not.
Any idea, how to solve this issue. I am using Clean Starter Kit with umbraco 8
public class ExperimentDataSource : FieldPreValueSourceType {
exception System.Web.HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Umbraco.Forms.Web.Models.FormViewModel.<>c.
is working on a reply...