我想在多视图上添加分页,但我收到错误

时间:2015-10-21 10:24:15

标签: c# asp.net-mvc entity-framework

我有多个视图但是在使用NuGet时出现错误。

这是我的控制器代码:

public ActionResult Index(string searchString, int? id, int? courseID, int? idcom, int? elencoimo, int? elecoimobi,int? elencoinsta)
    {
        var viewmodel = new mainview();

        viewmodel.elencoomonimi = db.ElencoOmonimis 
            .Where(s => s.Nome.Contains(searchString) || searchString == null || searchString == "")
            .Include(s => s.ElencoProvinces.Select(t => t.ElencoImmobiliPerDiritti_E_Quote))
            .Include(s => s.ElencoProvinces.Select(t => t.ElencoComunis))
            .Include(s => s.ElencoProvinces.Select(t => t.ElencoImmobiliPerDiritti_E_Quote.Select(r => r.ElencoIntestatis)))

            //.Include(i => i.ElencoOmonimi)
            //.Include(i => i.ElencoImmobiliPerDiritti_E_Quote.Select(t => t.ElencoIntestatis))
            //.Include(i => i.ElencoComunis)
            .OrderBy(i => i.Id);


        if (id != null)
        {
            ViewBag.elencoomonimiID = id.Value;
            viewmodel.elencoprovince = viewmodel.elencoomonimi.Where(
                i => i.Id == id.Value).Single().ElencoProvinces;
        }
        if (idcom != null)
        {
            ViewBag.ElencoImmobiliperID = idcom.Value;
            viewmodel.elencointestati = viewmodel.elencoimmobiliperditti.Where(
                x => x.Id == idcom.Value).Single().ElencoIntestatis;
        }

        if (elencoimo != null)
        {
            ViewBag.elecomuniID = elencoimo.Value;
            viewmodel.elencocomuni = viewmodel.elencoprovince.Where(
                r => r.Id == elencoimo.Value).Single().ElencoComunis;
        }
          if(elecoimobi != null)
          {
              ViewBag.ElencoimobID = elecoimobi.Value;
              viewmodel.elencoimmobiliperditti = viewmodel.elencoprovince.Where(
                  q => q.Id == elecoimobi.Value).Single().ElencoImmobiliPerDiritti_E_Quote;
          }

          if (elencoinsta != null)
          {
              ViewBag.ElencoInstatiID = elencoinsta.Value;
              viewmodel.elencointestati= viewmodel.elencoimmobiliperditti.Where(
                  e => e.Id == elencoinsta.Value).Single().ElencoIntestatis;
          }


        //if(elencoimo != null)
        //    ViewBag.elencoimoobiliID = id.Value
          //viewmodel.elencoimmobiliperditti = db.ElencoImmobiliPerDiritti_E_Quote
          //    .Include(r => r.ElencoIntestatis)
          //    .OrderBy(r => r.Classe);



        return View(viewmodel);
    }

这是我的观点:

@model automasis.Models.mainview

@{
    ViewBag.Title = "Index";
}

Dashboard



@using (Html.BeginForm())
{

    @Html.TextBox("SearchString") <br />
    <input type="submit" value="Filter" />
}

<table class="table">
    <tr>
        <th>
            Nome
        </th>
        <th>
            Cognome
        </th>
        <th>
            Nome Cercato
        </th>
        <th>
            Cognome Cercato
        </th>
        <th>
            Data Di Nascita
        </th>
        <th>
            Data Di Sesso
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model.elencoomonimi)
    {
        string selectedRow = "";
        if (item.Id == ViewBag.elencoomonimiID)
        {
            selectedRow = "success";
        }

        <tr class="@selectedRow">
            <td>
                @Html.DisplayFor(modelItem => item.Nome)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Cognome)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.NomeCercato)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.CognomeCercato)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.DataDiNascita)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Sesso)
            </td>
            @*@if (item.ElencoProvinces != null)
            {
                @item.ElencoProvinces
            }*@
            <td>
                @Html.ActionLink("Select", "Index", new { id = item.Id }) |
                @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
                @Html.ActionLink("Details", "Details", new { id = item.Id }) |
                @Html.ActionLink("Delete", "Delete", new { id = item.Id })
            </td>
        </tr>
    }

</table>
@if (Model.elencoprovince != null)
{
    <h3>Provinca</h3>
    <table class="table">
        <tr>
            <th></th>
            <th>Provincia</th>
            <th>Terreni</th>
            <th>Fabricati</th>

        </tr>

        @foreach (var item in Model.elencoprovince)
        {
            string selectedRow = "";
            if (item.Id == ViewBag.elencoprovinceID)
            {
                selectedRow = "success";
            }
            <tr class="@selectedRow">
                <td>
                    @Html.ActionLink("Immobiliper", "Index", new { elecoimobi = item.Id })
                </td>
                <td>
                    @Html.ActionLink("Comune", "Index", new { elencoimo = item.Id })
                </td>
                <td>
                    @item.Provincia
                </td>
                <td>
                    @item.Terreni
                </td>
                <td>
                    @item.Fabbricati
                </td>
                <td class="hidden">
                    @if (item.ElencoImmobiliPerDiritti_E_Quote != null)
                    {
                        @item.ElencoImmobiliPerDiritti_E_Quote
                    }
                </td>
            </tr>
        }

    </table>
}
@if (Model.elencocomuni != null)
{
    <h3>Elenco Comuni</h3>
    <table class="table">
        <tr>
            <th></th>
            <th>Particella</th>
            <th>Sub</th>
            <th>Titolarita</th>
            <th>Ubicazione</th>
            <th>Partita</th>
        </tr>

        @foreach (var item in Model.elencocomuni)
        {
            string selectedRow = "";
            if (item.Id == ViewBag.elecomuniID)
            {
                selectedRow = "success";
            }
            <tr class="@selectedRow">
                <td>
                    @Html.ActionLink("Select", "Index", new { id = item.Id })
                </td>
                <td>
                    @item.Comune
                </td>
                <td>
                    @item.Fabbricati
                </td>
                <td>
                    @item.Terreni
                </td>

            </tr>
        }

    </table>
}


@if (Model.elencointestati != null)
{
    <h3>elencoimmobiliperditti</h3>
    <table class="table">
        <tr>
            <th></th>
            <th>Particella</th>
            <th>Sub</th>
            <th>Titolarita</th>
            <th>Ubicazione</th>
            <th>Partita</th>
        </tr>

        @foreach (var item in Model.elencointestati)
        {
            string selectedRow = "";
            if (item.Id == ViewBag.ElencoInstatiID)
            {
                selectedRow = "success";
            }
            <tr class="@selectedRow">
                <td>
                    @Html.ActionLink("Select", "Index", new { id = item.Id })
                </td>
                <td>
                    @item.Nominativo
                </td>
                <td>
                    @item.Titolarita
                </td>


            </tr>
        }

    </table>
}
@if (Model.elencoimmobiliperditti != null)
{
    <h3>elencoimmobiliperditti</h3>
    <table class="table">
        <tr>
            <th></th>
            <th>Particella</th>
            <th>Sub</th>
            <th>Titolarita</th>
            <th>Ubicazione</th>
            <th>Partita</th>
        </tr>

        @foreach (var item in Model.elencoimmobiliperditti)
        {
            string selectedRow = "";
            if (item.Id == ViewBag.ElencoInstatiID)
            {
                selectedRow = "success";
            }
            <tr class="@selectedRow">
                <td>
                    @Html.ActionLink("Select", "Index", new { elencoinsta = item.Id })
                </td>
                <td>
                    @item.Classe
                </td>
                <td>
                    @item.Consistenza
                </td>
                <td>
                    @item.Foglio
                </td>
                <td class="hidden">
                    @if (item.Partita != null)
                    {
                        @item.Rendita
                    }
                </td>
            </tr>
        }

    </table>
}

0 个答案:

没有答案