C# 如何为使用scaffold创建视图时创建的输入元素清空编辑器。
我创建了一个viewmodel,如下所示:C# 如何为使用scaffold创建视图时创建的输入元素清空编辑器。,c#,asp.net-mvc,razor,C#,Asp.net Mvc,Razor,我创建了一个viewmodel,如下所示: public class M_Master { public string SUPWH { get; set; } public string STKGL { get; set; } public string SALGL { get; set; } public string COSGL { get; set; } public decimal ROQ { get; set; } publi
public class M_Master
{
public string SUPWH { get; set; }
public string STKGL { get; set; }
public string SALGL { get; set; }
public string COSGL { get; set; }
public decimal ROQ { get; set; }
public int MIN { get; set; }
public int MAX { get; set; }
public int LT { get; set; }
public string PRODSPEC { get; set; }
public string REMK1 { get; set; }
public string REMK2 { get; set; }
public decimal openingQty { get; set; }
public decimal openingAmt { get; set; }
public decimal onHandQty { get; set; }
public decimal ytdReceiptQty { get; set; }
}
然后我使用这个ViewModel创建一个视图。因此,视图如下所示:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>INV_Master</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.PROD, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.PROD, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.PROD, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.WH, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.WH, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.WH, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DESCR, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DESCR, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DESCR, "", new { @class = "text-danger" })
</div>
</div>
@使用(Html.BeginForm())
{
@Html.AntiForgeryToken()
投资主管
@Html.ValidationSummary(true,“,new{@class=“text danger”})
@LabelFor(model=>model.PROD,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.PROD,new{htmlAttributes=new{@class=“form control”}})
@Html.ValidationMessageFor(model=>model.PROD,“,new{@class=“text danger”})
@LabelFor(model=>model.WH,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.WH,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.WH,“,new{@class=“text danger”})
@LabelFor(model=>model.DESCR,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.DESCR,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.DESCR,“,new{@class=“text danger”})
我意识到,当我访问页面/视图时,默认情况下,html
input
字段中的值为0,用于ViewMoel中的int、decimal、datetime等属性。如何确保所有input
字段默认为空?使用int?、decimal?和datetime?等可为空的类型。W实例化对象时,每个属性都将初始化为数据类型默认值。Int默认值为0,Int?默认值为null。依此类推。您仍然可以放置一个[Required]将int
更改为int?
?将那些不可为null的类型更改为可为null,例如int
=>int?
,十进制
,日期时间
。