0

This method is used to auto-generate some Html fields to reduce code duplication. It works perfectly fine when I host it locally:

static string GenerateTextField<DBType, FieldType>(this HtmlHelper<DBType> 
page, Expression<Func<DBType, FieldType>> fieldExp, string formControlData)
{
        var model = page.ViewData.Model;

        var fieldName = 
            ExpressionHelper.GetExpressionText(fieldExp).Split('.').Last();
        var formatRules = new CultureInfo("en-EN");
        string valueText = "";

        var value = model != null?
            fieldExp.Compile()(model): 
            default(FieldType);
        if (typeof(FieldType).IsAssignableFrom(typeof(float))) valueText = 
            ((float)(object)value).ToString(formatRules);
        else valueText = value?.ToString();

        System.Diagnostics.Debug.WriteLine("valueText =" + valueText);

        return [html text, converted to MvcHtmlString elsewhere];
}

However, when I export it to be hosted by Azure web app and run it there, it announces: Culture is not supported. Parameter name: name en-EN is an invalid culture identifier.

I am aware of the topic Culture is suddenly not supported anymore on Azure web app. The problem is that the remedy suggested there concetrates on how to build a RegionInfo, which I'm not even using.

I need that formatting with english culture because the html field uses a custom numeric spinner which tructates the database value if it is entered with a decimal comma instead of a decimal point.

I can of course format the string by hand, but is there a better solution?

dukc
  • 121
  • 1
  • 9
  • Wouldn't the InvariantCulture work for that? It uses a decimal point. – stuartd Jun 07 '17 at 09:59
  • Don't know about that... I'll try to find it. – dukc Jun 07 '17 at 10:02
  • It's [CultureInfo.InvariantCulture](https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.invariantculture%28v=vs.110%29.aspx) - _"The invariant culture is culture-insensitive; it is associated with the English language but not with any country/region."_ – stuartd Jun 07 '17 at 10:05
  • Thanks, I'm just testing it. Trough, I have to say that things that surface like this -only after publication, not locally- are dangerous. I'm probably doing something wrong altogether. – dukc Jun 07 '17 at 10:09
  • Your solution worked, trough. Thanks again. – dukc Jun 07 '17 at 10:11
  • 2
    I think the problem might be that `"en-EN"` isn't a valid culture name - see [this question](https://stackoverflow.com/questions/34138398/can-create-culture-for-en-en-on-local-dev-machine) - `"en-US"` would be the usual choice. – stuartd Jun 07 '17 at 10:13

0 Answers0