i want save value in sql server database but i have this error , but i don't use identity
i want save value that i write in textbox.
this is CenterLocation model class:-
public partial class CenterTechnical
{
public int ID { get; set; }
public string LocationCenterID { get; set; }
public string TechName { get; set; }
public string TechMobile { get; set; }
public string TechPhone { get; set; }
public string TechAddress { get; set; }
public virtual LocationCenter LocationCenter { get; set; }
}
and this is create methos in controller:-
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ID, LocationCenterID, TechName, TechMobile, TechPhone, TechAddress")]CenterTechnical centerTechnical)
{
if(ModelState.IsValid)
{
var newTechnical = new CenterTechnical()
{
ID = centerTechnical.ID,
LocationCenterID = centerTechnical.LocationCenterID,
TechName = centerTechnical.TechName,
TechMobile = centerTechnical.TechMobile,
TechPhone = centerTechnical.TechPhone,
TechAddress = centerTechnical.TechAddress
};
db.CenterTechnical.Add(newTechnical);
db.SaveChanges();
return RedirectToAction("Index");
}
else
{
return View(centerTechnical);
}
}
View :-
@using (Html.BeginForm("Create", "CenterTechnical", FormMethod.Post, new { enctype = "form-data" }))
{
@Html.AntiForgeryToken()
<div class="row">
<div class="col-md-12">
<div class="box box-DG">
<div class="box-header with-border">
<span style="color:#2D69B7"></span>
<h3 class="box-title">@WhiteWhaleLanguage.Technical</h3>
</div>
<div class="box-body">
<div class="row">
<div class="col-md-12">
<div class="form-horizontal">
<div class="form-group">
@Html.LabelFor(model => model.ID, @WhiteWhaleLanguage.TechnicalID, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-6">
<div class="">
@Html.TextBoxFor(model => model.ID, new { @class = "form-control" })
</div>
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.LocationCenterID, @WhiteWhaleLanguage.CenterCode, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-6">
<div class="">
@Html.TextBoxFor(model => model.LocationCenterID, new { @class = "form-control" })
</div>
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TechName, @WhiteWhaleLanguage.TechName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-6">
<div class="">
@Html.TextBoxFor(model => model.TechName, new { @class = "form-control" })
</div>
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TechMobile, @WhiteWhaleLanguage.TechMobile, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-6">
<div class="">
@Html.TextBoxFor(model => model.TechMobile, new { @class = "form-control" })
</div>
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TechPhone, @WhiteWhaleLanguage.TechPhone, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-6">
<div class="">
@Html.TextBoxFor(model => model.TechPhone, new { @class = "form-control" })
</div>
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TechAddress, @WhiteWhaleLanguage.TechAddress, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<div class="">
@Html.TextAreaFor(model => model.TechAddress, new { @class = "form-control", @rows = "5" })
</div>
</div>
</div>
<br />
<div class="modal-footer with-border">
<input type="submit" name="" value=@WhiteWhaleLanguage.SaveNewTechnical , class="btn btn-primary col-md-2" />
@Html.ActionLink(WhiteWhaleLanguage.BackToList, "Index", null, new { @class = "btn btn-default" })
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
}
What I have tried:
i want add value in textbox and save values and i don't use identity