Drop down lis and search in MVC # database first
I'm begginer and This my First Large MVC3 App using Entity Framework Model.
This is a image of the .EDMX Model that I am using
I create Candidate and Skill Controler,strongli tipe view for edit, detail, and delete.
public class CandidateController : Controller
{
private Models.CandidatEntities data;
public CandidateController()
{
data = new CandidatEntities();
}
public ActionResult Index()
{
var candidates = data.Candidate.ToList();
return View(candidates);
}
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(Candidate candidate)
{
if (!ModelState.IsValid)
{
return View(candidate);
}
data.Candidate.AddObject(candidate);
data.SaveChanges();
return RedirectToAction("Index");
}
public ActionResult Details(int id)
{
var candidate = data.Candidate.Where(c => c.CandidateID == id).First();
return View(candidate);
}
public ActionResult Edit(int id)
{
var candidate = data.Candidate.Where(c => c.CandidateID == id).First();
return View(candidate);
}
[HttpPost]
public ActionResult Edit(Candidate candidate)
{
var candidateToEdit = data.Candidate.Where(c => c.CandidateID == candidate.CandidateID).First();
candidateToEdit.FirstName = candidate.FirstName;
candidateToEdit.LastName = candidate.LastName;
candidateToEdit.Email = candidate.Email;
data.SaveChanges();
return RedirectToAction("Index");
}
public ActionResult Delete(int id)
{
var candidate = data.Candidate.Where(c => c.CandidateID == id).First();
return View(candidate);
}
[HttpPost]
public ActionResult Delete(Candidate candidate)
{
var candidateToDelete = data.Candidate.Where(c => c.CandidateID == candidate.CandidateID).First();
data.DeleteObject(candidateToDelete.FirstName);
data.DeleteObject(candidateToDelete.LastName);
data.DeleteObject(candidateToDelete.Email);
data.SaveChanges();
return RedirectToAction("Index");
}
For this method I have problem:
Sequence contains no elements
I need to add drop down list for skill and add a text box for entering a skillLevel and a button search wich return list of candidate for selected Skill and skillLevel.
I really do appriciate for any help.