【发布时间】:2011-03-30 15:58:38
【问题描述】:
当尝试使用db_ent.SaveChanges() 将数据保存到数据库时,我遇到了这个错误:
文化“sr”是一种中性文化。它不能用于格式化和解析,因此不能设置为线程的当前文化。有什么解决办法吗?
编辑:
我的路由本地化助手
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Threading;
using System.Globalization;
namespace darns.Helpers
{
public class MultiCultureMvcRouteHandler : MvcRouteHandler
{
protected override IHttpHandler GetHttpHandler(System.Web.Routing.RequestContext requestContext)
{
String culture = requestContext.RouteData.Values["culture"].ToString();
var ci = new CultureInfo(culture);
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
return base.GetHttpHandler(requestContext);
}
}
public class SingleCultureMvcRouteHandler : MvcRouteHandler {}
public class CultureConstraint : IRouteConstraint
{
private string[] _values;
public CultureConstraint(params string[] values)
{
this._values = values;
}
public bool Match(HttpContextBase httpContext,Route route,string parameterName,
RouteValueDictionary values, RouteDirection routeDirection)
{
// Get the value called "parameterName" from the
// RouteValueDictionary called "value"
string value = values[parameterName].ToString();
// Return true is the list of allowed values contains
// this value.
return _values.Contains(value);
}
}
public enum Culture
{
sr = 1,
hr = 2,
en = 3,
ru = 4
}
/// <summary>
/// Util class for storing error message pairs
/// </summary>
/// <typeparam name="E"></typeparam>
/// <typeparam name="T"></typeparam>
public class ErrorPair<E, T>
{
public E Key { get; set; }
public T Message { get; set; }
public ErrorPair(E key, T message)
{
Key = key;
Message = message;
}
}
}
【问题讨论】:
标签: asp.net-mvc