Why am i getting the following error:
Object reference not set to an instance of an object.
I know it it becouse it tells me it' can't save it as a "null" But there are a value in it, or am i doing it wrong? I have tryed diffrent ways aswell without seeing how i should do it?
Model:
public class BookTime
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public int Zip { get; set; }
public string City { get; set; }
public string Address { get; set; }
public string Month { get; set; }
public string Date { get; set; }
}
Controler:
public ActionResult _BookTime(BookTime Booktime)
{
db.BookTimes.Add(Booktime);
Booktime.Month = Request.Form["Month"].ToString();
Booktime.Date = Request.Form["Date"].ToString();
db.SaveChanges();
return Redirect("Index");
}
View:
<div class="col-sm-6">
<b>Månede</b>
<select class="form-control" id="Month" required>
<option value="0">Vælg Dag</option>
<option value="Januar">Januar</option>
<option value="Febuar">Febuar</option>
<option value="Marts">Marts</option>
<option value="April">April</option>
<option value="Maj">Maj</option>
</select>
</div>
<div class="col-sm-6">
<b>Dag</b>
<select class="form-control" id="Date" required>
<option value="0">Vælg Dato</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>