我正在使用下拉列表的车辆类型,其值将来自数据库,但是当我单击“创建”按钮时,我会得到
系统参数空引用异常。
我有三个模型类:VehicleInfo
,Vehicle
,Type
我尝试使用ViewBag和其他方法绑定模型数据。
@model TeslaCompany.Models.VehicleInfo
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm("Create","Vehicle",FormMethod.Post)) {
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>VehicleInfo</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.VehicleId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("Type",new SelectList(ViewBag.data,"TypeId","Type"))
@* @Html.DropDownListFor(model=>model.vehicleList,new SelectList(Model.vehicleList,"TypeId","Type"),"Select")
@@Html.DropDownListFor(model => model.VehicleId, (SelectList)ViewBag.MyGroups)*@
@*@Html.ValidationMessageFor(model => model.vehicleList, "", new { @class = "text-danger" })*@
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Model, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Model, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Model, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ColorId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ColorId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.colorList, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Price, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Price, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Price, "", 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")
}