I got this error
LINQ to Entities does not recognize the method 'System.String Format(System.String, System.Object, System.Object)' method, and this method cannot be translated into a store expression.
What I am trying to do is to list all of my values in my database.
Here is the code in my view:
<div class="col-md-10">
@Html.DropDownList("SelectedScheduleId", Model.ScheduleSelectListItems, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.sched_id, "", new { @class = "text-danger" })
</div>
Here is my class in my model:
public class BookingModel
{
[Required]
[StringLength(200, ErrorMessage = "Description too short. Must be at least {2} characters long", MinimumLength = 10)]
[Display(Name = "Describe your Consultation")]
public string appointment_description { get; set; }
public int appointment_id { get; set; }
public int student_id { get; set; }
public int sched_id { get; set; }
public sched sched { get; set; }
public IEnumerable<SelectListItem> ScheduleSelectListItems { get; set; }
public int SelectedScheduleId { get; set; }
}
and my controller:
public ActionResult Book()
{
var items = db.scheds.Select(sched => new SelectListItem { Text = string.Format("{0} - {1}", sched.sched_stime, sched.sched_etime), Value = sched.sched_id.ToString() });
var model = new BookingModel { ScheduleSelectListItems = items };
return View(model);
}
I just want to place the values of my sched table into a dropdown list.
I have consulted someone about how to list values of the foreign key and now I've ended up with a new error. How can I fix this? This is the only thing standing between me and finishing my project. :(