Error 500 in Asp.Net Awesome Library

Asked

Viewed 183 times

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 !

  • 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.

  • I already did, I did an update on the bug I’m having !

1 answer

4


Come on, I solved the problem. The problem is that I think the code is kind of old, and so it didn’t work well the way it is on the site. So I researched and used as a reference this link here. what happens is that he was not able to connect with the bank to make the list, so I had to adapt the code, which is just below for those who want to use the library also:

public class AlunoLookupController : Controller
{
    private EntidadesContext db = new EntidadesContext();
    public ActionResult GetItem(int? v)
    {
        var o = db.Alunos.SingleOrDefault(f => f.Id == v) ?? new Aluno();

        return Json(new KeyContent(o.Id, o.Nome));
    }

    public ActionResult Search(string search, int page)
    {
        search = (search ?? "").ToLower().Trim();
        var lista = db.Alunos.Where(f => f.Nome.Contains(search)).ToList();
        return Json(new AjaxListResult
        {
            Items = lista.OrderBy(f => f.Nome).Skip((page - 1) * 7).Take(7).Select(o => new KeyContent(o.Id, o.Nome)),
            More = lista.Count() > page * 7
        });
    }
}

Remembering that this code up there, has to be in the controller that you want to manipulate the information, but outside of the normal actions that are created, for example Home, it has to be below this action, but in the same class as below:

 public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

And under it is the controller code that ASP.net Awesome uses:

public class AlunoLookupController : Controller
{
    private EntidadesContext db = new EntidadesContext();
    public ActionResult GetItem(int? v)
    {
        //Os códigos das actions
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.