I found browsing this library ASP.net Awesome
. I found it to be very functional and easy to use.
According to the documentation for using a helper named Lookup
, you must have a controller
and call the helper in cshtml in>. What happens is that, in my project, it is exactly the same as the documentation ( the code ), and I'm having an error 500 and I do not know exactly why.
I already researched and could not solve the error, could anyone help me?
- Explaining Lookup does: It opens a popup with a list of what's in your table for you to select and populate a text field. You can search to find exactly what you want. And it is exactly in this Search method that is giving error, it would have to load all my records from the database, the names of the students. but it gives error 500 .
The controller code is this:
public class AlunoLookupController : Controller
{
private EntidadesContext db = new EntidadesContext();
//Aqui ele pega o item que foi selecionado e joga no campo de texto
public ActionResult GetItem(int? v)
{
var o = db.Alunos.SingleOrDefault(f => f.Id == v) ?? new Aluno();
return Json(new KeyContent(o.Id, o.Nome));
}
// E aqui ele faz a busca dos registros no banco e exibe no popup
//E aqui tabém dá erro, ele não acha nenhum registro e só fica carregando
public ActionResult Search(string search, int page)
{
search = (search ?? "").ToLower().Trim();
var list = db.Alunos.Where(f => f.Nome.ToLower().Contains(search));
return Json(new AjaxListResult
{
Items = list.OrderBy(n => n.Nome).Skip((page - 1) * 7).Take(7).Select(o => new KeyContent(o.Id, o.Nome)),
More = list.Count() > page * 7
});
}
}
I'm sure that problem is in the code I pulled from there, but I do not know what's going on.
The error that appears is as follows:
Description: An unhandled exception occurred during the execution of the current Web request. Examine the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NotSupportedException: Only parameterless constructors and initializers are supported in LINQ to Entities.