I am trying to store the details from form to database using entity framework, i am using enum to store dropdown content.while submitting i am facing issue. issue: System.InvalidOperationException: 'The entity type socialwebtable is not part of the model for the current context.'
[HttpPost]
public ActionResult register(socialwebtable c1)
{
socialwebsiteEntities db = new socialwebsiteEntities();
//data1 is a table name
socialwebtable data23 = new socialwebtable();
data23.name = c1.name;
data23.bloodgroup = c1.bloodgroup;
data23.city = c1.city;
data23.phonenumber = c1.phonenumber;
db.socialwebtables.Add(data23);
// db.socialwebtables.InsertOnSubmit(data23);
db.SaveChanges();
return View();
}
View:
<div class="form-group">
@Html.LabelFor(model => model.bloodgroup, htmlAttributes: new {
@class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EnumDropDownListFor(
x => x.bloodgroup,
"Select My Type",
new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.bloodgroup, "", new {
@class = "text-danger" })
</div>
</div>
Model:
public enum enum1
{
[Display(Name = "O+")]
O,
[Display(Name = "A+")]
B,
[Display(Name = "B+")]
A,
[Display(Name = "AB+")]
AB,
[Display(Name = "O-")]
O1,
[Display(Name = "A-")]
B1,
[Display(Name = "B-")]
A1,
[Display(Name = "AB-")]
AB1,
}
public partial class socialwebtable
{
public int id { get; set; }
public string name { get; set; }
public enum1 bloodgroup { get; set; }
public string city { get; set; }
public decimal phonenumber { get; set; }
}
}