我是ASP.NET EF6的新手,需要一些帮助,我创建了一个datamodel和一个datacontext
public class RepositoryDbContext : DbContext
{
public RepositoryDbContext()
: base("DefaultConnection")
{
}
public DbSet<Repository> Repositories { get; set; }
}
public class Repository
{
public int ID { get; set; }
public string SKU { get; set; }
public string Title { get; set; }
}
和html页面
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Order</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.SKU, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.SKU, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.SKU, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
然后我使用Visual Studio 2015自动创建控制器和视图,但是在创建页面中,sku和title都是必需的,我怎么能摆脱Title字段所需的验证。
非常感谢,我尝试使用谷歌搜索但没有运气。