<分区>
我拼命地尝试让 asp.net 使用逗号作为小数点分隔符,但这似乎比必要的要难得多......
我已经完成了本教程中的所有内容 http://www.asp.net/mvc/overview/getting-started/introduction/examining-the-edit-methods-and-edit-view
在根网络配置中尝试过
<system.web>
<globalization culture="de-DE" uiCulture="de-DE" />
</system.web>
单步执行 jQuery 代码 - 那里的全局化似乎有效。
我正在使用一个带有 Model View Controller 的获取请求,看起来像这样
public class SearchCalcViewModel
{
public SearchCalcViewModel() { }
public IEnumerable<Calculation> Calculations { get; set; }
[Display(Name="Name")]
public string Name { get; set; }
[Display(Name="Height")]
public decimal? Height { get; set; }
}
get 请求在主 Controller 中被调用 - 因此这加强了我的假设,即 jquery 文化相关验证正在工作,并且 .net 文化中的某些东西是错误的,即使 Thread.CurrentTHread.CurrentCulture/CurrentUICulture 也设置正确。
当我尝试填写 3,0 作为高度时,我收到以下错误消息:
值“3,0”对高度无效。
这是我观点的重要部分:
@using (Html.BeginForm("Search", "Main", FormMethod.Get))
<div class="form-group">
@Html.LabelFor(m => m.Height, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Height, new { @class = "form-control"})
@Html.ValidationMessageFor(m => m.Height)
</div>
</div>
}
这是我的主 Controller :
public ActionResult Search(SearchCalcViewModel searchViewModel)
{
searchViewModel.Products = db.Products;
searchViewModel.Calculations = from c in db.Calculations select c;
if (searchViewModel.Height.HasValue)
{
searchViewModel.Calculations = searchViewModel.Calculations.Where(c => c.Length == searchViewModel.Height);
}
return View(searchViewModel);
}
我已经进入模特状态,不知何故文化与我现在的文化不同