我有他的密码。部分视图。
<div class="input width110">
@Html.EditorFor(x => x.Price, @Html.Attributes(@class: "right_text_align", @disabled: "true", @id: "Price"))
</div>
模型。
public class ServiceModel
{
[DisplayFormat(DataFormatString = "{0:0.00}", ApplyFormatInEditMode = true)]
public decimal Price { get; set; }
}
控制器
public ActionResult SetService(ServiceModel model, string action)
{
if (ModelState.IsValid)
{
/*Does smthg.*/
ModelState.Clear();
}
return View("Index", rcpModel);
//Index is main view, which holds partialView
//rcpModel holds, model
}
当视图加载时,十进制以格式“0.00”显示。但是在发布后,当modelState 是无效数字时,以“0.0000”格式显示。如果模型状态有效,则一切顺利。有没有人遇到过类似的事情?