Hi:
I'm using this code in a SharePoint 2013 webpart in order to show the stars rating for an item, but I'm having a problem
with the average Rating format:
{
using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
{
web.AllowUnsafeUpdates = true;
AverageRatingFieldControl PageRatingControl = new AverageRatingFieldControl();
PageRatingControl.ID = "RatingCntrl";
PageRatingControl.ListId = _contenidoList.ID;
PageRatingControl.ControlMode = SPControlMode.Edit;
PageRatingControl.FieldName = "AverageRating";
PageRatingControl.ItemContext = SPContext.GetContext(HttpContext.Current,
item.ID,
_contenidoList.ID,
web);
divRating.Controls.Add(PageRatingControl);
web.AllowUnsafeUpdates = false;
}
}
If I look into the script that is injected with this code I found the following:
EnsureScript('SP.UI.Ratings.js', typeof(SP.UI.Reputation), function () {
var avgRating = 3,66666666666667;var ratingCount = '0';var ratings = '';var ratedBy = '';var itemId = 6;var userId = 27921;var listId = '22b81e75-f22d-4c76-8003-13962b016efb';var listTemplate = 'GenericList';var elmCtrl = $get('RatingsCtrl_ctl00_ctl52_g_33e57148_fbe8_401e_bcc8_60548492189a_RatingCntrl');
Uncaught SyntaxError: Unexpected number
If you can see, the avgRating variable is filled with a '3,666666666667'
instead of a '3.666666666667' so the script is throwing an exception "Unexpected number". If the average rating is an exact integer, the control works just fine. Is it possible to force a specific culture so it tooks the correct decimal format? Or
there is any other way to get around this issue? We are using the Spanish Language Pack.
Regards,
Gustavo