when I try to add in my model some note appear Exception
Here is my CompetitionRepository where I implement method
public void AddCompetition(Competition competition)
{
if (competition.ID == 0)
_context.Competitions.Add(competition);
else
_context.Entry(competition).State = EntityState.Modified;
_context.SaveChanges();
}
Controller
[HttpPost]
public ActionResult AdminPCreate(string compName, int quantity, DateTime starTime)
{
if(ModelState.IsValid)
_dataManager.Competitions.AddCompetition(
new Competition
{
ID = 1,
Quantity = quantity,
StartTime = starTime,
});
return View("Competitions",GetCompetitions());
}
And cshtml Page, maybe I'm doing something wrong
@using (Html.BeginForm("AdminPCreate", "Home"))
{
@Html.TextBox("compName",null ,new {@placeholder = "Competition Name"})
@Html.TextBox("quantity", null, new {@placeholder = "Amount players"})
@Html.TextBox("starTime", null, new {@placeholder = "Enter beginnig of the match like dd\\mm\\yyyy"})
<input type="submit" value="Create" class="btn btn-success"/>
I also tried using a lot of solutions including here on that site, such as that because when i try to use that (ObjectStateManager.GetObjectStateEntry(entity)` because my field methods have type different from object
public void AddCompetition(Competition competition)