1
I found browsing the internet this library ASP.net Awesome
. I found it very functional and easy to use.
According to the documentation to use a helper called Lookup
, you need to have a controller
and call the helper in the cshtml. What happens is that, in my project, it’s exactly the same as the documentation(the code), and having a error 500 and I don’t know exactly why.
I have already researched and I could not solve the error, I wonder if someone could help me ?
- Explaining the Lookup does: It opens a popup with a list of what you have in your table for you to select and popular a text field. You can do a search to find exactly what you want. And it’s exactly in this method Search which is giving error, he would have to upload all my records from the database, the students' names. but he 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 there’s a problem with the code I pulled from there, but I don’t know what’s going on.
The error that appears is as follows:
Description: An untreated exception occurred during the execution of the current web request. Examine stack tracking 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.
Can anyone help me ? I tried to use it here according to the documentation, but it did not work at all... VS does not recognize the dll and does not recognize anything !
– Érik Thiago
You can [Dit] your question by explaining better what you are trying to do and what is going wrong. Make the question more specific and give details so people can understand the problem and help you.
– bfavaretto
I already did, I did an update on the bug I’m having !
– Érik Thiago