How do I correct this error, and was able to see this other table in my view?

Asked

Viewed 158 times

0

I need to make a select with two tables and play the result for a PagedList. But when I query, returns the error:

Cannot implicitly Convert type 'Pagedlist.Ipagedlist' to 'Pagedlist.Ipagedlist<>'. An Explicit Conversion exists (are you Missing a cast?) C: IIS System Controllers Titcontroller.Cs

But when I remove the Join, he does not return the error. How to correct this error, and I could see this other table in my view?

Follow the code below:

public ActionResult ConTitulos(int? Pagina, string Pesquisa, decimal? NProtocolo, For model)
{
        var entities = new Model();
        if (!string.IsNullOrEmpty(Pesquisa) || Pagina.HasValue)
        {

            var results = entities.For
                .Join(entities.Dev,
                t => t.For_Dev_ID,
                h => h.Dev_ID,
                (t, h) => new
                {
                t.For_Nome,
                h.Dev_Nome
                })
                .Where(b => b.Protocolo == NProtocolo).AsEnumerable();

            var pageIndex = Pagina ?? 1;
            model.ProcuraResultados = results.ToPagedList(pageIndex, RecordsPerPage);


        }
        if (model.ProcuraResultados != null && model.ProcuraResultados.Count == 1)
        {
            foreach (var item in model.ProcuraResultados)
            {
                return RedirectToAction("Devedores", new { id = item.For_ID });
            }

        }
        return View(model);
}

View

@model Sistema.Models.for
@{
  ViewBag.Title = "Consulta de Devedores";
}
@using PagedList.Mvc;
<h2>Consulta de Devedores</h2>
<div id="page-wrapper">
  <div class="content-wrapper">
    <div class="container-fluid">
        @using (Html.BeginForm("ConTitulos", "Devedores", FormMethod.Get))
        {
            <table width="100%">
                <tr>
                    <td class="tblNormal">Nº do Protocolo</td>
                </tr>
                <tr>
                    <td class="tblNormal">
                        <input type="text" name="NProtocolo" onkeypress="FiltraTecla(event);" size="10" maxlength="10" value="">
                        @*@Html.EditorFor(model => model.TIT_PRT_CRT, new { htmlAttributes = new { @class = "form-control", name= "NProtocolo",size = "10", maxlength = "10", value = "" } })*@
                    </td>
                </tr>
            </table>
            if (Model.ProcuraResultados != null && Model.ProcuraResultados.Count > 1)
            {
                <div>
                    <br />
                    <table class="table">
                        <tr>
                            <th>Devedor</th>
                            <th>Fornecedor</th>
                        </tr>
                        @foreach (var item in Model.ProcuraResultados)
                        {
                            <tr>
                                <td class="control-label">@item.Dev_nome</td>
                                <td class="control-label">@item.For_Nome</td>
                                <td>
                                    @Html.ActionLink("Alterar", "AltDevedor", new { id = @item.DEV_ID }, null)
                                </td>
                            </tr>
                        }
                    </table>
                </div>
                @Html.PagedListPager(Model.ProcuraResultados, page => Url.Action("ConTitulos", new RouteValueDictionary()
      {
           { "Pagina", page },
           { "Apresentante", Model.Dev_nome },
           { "Devedor", Model.For_Nome }
      }),
      PagedListRenderOptions.PageNumbersOnly)
            }
        }
        </div>
    </div>
</div>
  • Welcome Germano. You can post your view also?

  • I put the View too!

2 answers

0


Dude, try this.

@model Sistema.Models.for
@{
  ViewBag.Title = "Consulta de Devedores";
}
@using PagedList.Mvc;
<h2>Consulta de Devedores</h2>
<div id="page-wrapper">
  <div class="content-wrapper">
    <div class="container-fluid">
        @using (Html.BeginForm("ConTitulos", "Devedores", FormMethod.Get))
        {
            <table width="100%">
                <tr>
                    <td class="tblNormal">Nº do Protocolo</td>
                </tr>
                <tr>
                    <td class="tblNormal">
                        <input type="text" name="NProtocolo" onkeypress="FiltraTecla(event);" size="10" maxlength="10" value="">
                        @*@Html.EditorFor(model => model.TIT_PRT_CRT, new { htmlAttributes = new { @class = "form-control", name= "NProtocolo",size = "10", maxlength = "10", value = "" } })*@
                    </td>
                </tr>
            </table>
            if (Model.ProcuraResultados != null && Model.ProcuraResultados.Count > 1)
            {
                <div>
                    <br />
                    <table class="table">
                        <tr>
                            <th>Devedor</th>
                            <th>Fornecedor</th>
                        </tr>
                        @foreach (var item in Model.ProcuraResultados)
                        {
                            <tr>
                                <td class="control-label">@item.Dev_nome</td>
                                <td class="control-label">@item.For_Nome</td>
                                <td>
                                    @Html.ActionLink("Alterar", "AltDevedor", new { id = @item.DEV_ID }, null)
                                </td>
                            </tr>
                        }
                    </table>
                </div>
                @Html.PagedListPager(Model, page => Url.Action("ConTitulos", new RouteValueDictionary()
      {
           { "Pagina", page },
           { "Apresentante", Model.Dev_nome },
           { "Devedor", Model.For_Nome }
      }),
      PagedListRenderOptions.PageNumbersOnly)
            }
        }
        </div>
    </div>
</div>
  • What was the change you made?

  • Only in @Html.Pagedlistpager(Model, page => Url.Action("Contents", new Routevaluedictionary()

  • My view logic is correct, the problem is in my Controller that does not send querie data to the variable Search & #Xa;where it will be used for paging logic. model.Search results = Results.Topagedlist(pageIndex, Recordsperpage);

  • Is there a Search Data type? or are you trying to send anonymity to the seen?

  • The attorney you speak of is the . Select?

  • Searching

  • The Prosecutor is a pagedlist type within the model.

  • Okay, but your view is waiting for a @model System.Models.for and you are not returning this type in your var Results = entities. For . Join(entities.Dev, t => t.For_dev_id, h => h.Dev_id, (t, h) => new { t.For_name, h.Dev_name }) . Where(b => b.Protocol == Nprotocolo). Asenumerable();

  • I changed the pagedList logic to ajax and it worked!

Show 4 more comments

0

This does not return List<for>:

var results = entities.For
            .Join(entities.Dev,
            t => t.For_Dev_ID,
            h => h.Dev_ID,
            (t, h) => new
            {
            t.For_Nome,
            h.Dev_Nome
            })
            .Where(b => b.Protocolo == NProtocolo).AsEnumerable();

This returns an anonymous object with two properties: For_Nome and Dev_Nome. This will conflict with what we have on View, therefore the mistake:

@model Sistema.Models.for

Like you tell View one IPagedList, change to:

@using PagedList
@model IPagedList

Browser other questions tagged

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