I don't understand why this is happening but the website works fine until you try to access the create a booking View and it throws a "NotSupportedException was unhandle by user code" Error.

This is the part where the error gets thrown from the ViewBag onwards:

    // GET: /Home/BookaFlight
    public ActionResult BookaFlight()
        ViewBag.FlightsList = (from L in ss.FlightsTbls select new { ID = L.Flight_Id, text = L.Departing_Airport + "to" + L.Arriving_Airport + " " + L.Daily_Flight_Number }).ToList();
        return View();

This relevant code for the model storing the data for the dropdown and so on:

namespace Assignment_2_Flight_Booking_Website.Models
public class BookingValidation

    public int Flight_ID { get; set; }


And finally the view which won't open (Only dropdown part shown):


@using (Html.BeginForm())

<td>@Html.DropDownListFor(Model => Model.Flight_ID, new SelectList(ViewBag.FlightsList, "ID", "text"))</td>

Please help I haven't a clue whats going wrong and I also want to mention it's all being stored on an SQL database. I can't see whats causing the error at first I though it might be to do with The Flight_ID being stored as an int and not a String but converting it to a string does nothing and just won't work. it worked before I added the dropdown.

Error details:

An exception of type 'System.NotSupportedException' occurred in System.Data.Entity.dll but was not handled in user code Additional information: Unable to cast the type 'System.Int32' to type 'System.Object'. LINQ to Entities only supports casting EDM primitive or enumeration types.

Related posts

Recent Viewed