I have this silly problem, which I hope someone could help me enlighten. I am building an extension for Umbraco7's backoffice, for that I need to receive a simple string. My problem is the string return from the REST api contain double quotes and then AngularJS wont model bind. Here's my API method:
public String GetWeek()
{
var datetime = DateTime.Now;
var cultureInfo = new CultureInfo("da-DK");
var calendar = cultureInfo.Calendar;
var week = calendar.GetWeekOfYear(datetime, cultureInfo.DateTimeFormat.CalendarWeekRule, cultureInfo.DateTimeFormat.FirstDayOfWeek);
return datetime.Year + "-W" + week;
}
If someone could explain, how I get rid of these double quotes, I will be really grateful :)
The result:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">"2015-W24"</string>
I found another way than @basarat is suggesting, from the comment form @ArghyaC. The problem is that Umbraco's REST controller builds on asp.net's ControllerApi, and defaults to xml. The apostrophes comes from the xml serialize. The solution is simple force json as the return value instead. I don't dare to change this globally, but can force a method to return with the JsonResult return value:
This solves the problem too, but without doing anything in the client.