Загрузка частичного представления, имеющего сложную модель многих подмоделей, во вкладку пользовательского интерфейса jquery - PullRequest
0 голосов
/ 20 декабря 2018

Я получаю сообщение об ошибке при загрузке определенного представления с помощью вызова Html.action для действия и контроллера, на вкладку jquery.Другое представление успешно загружается с помощью вызова HTML.Partial.Как мне загрузить эту другую частичку, пожалуйста.

Вкладка, где происходит ошибка, является tab4.Закомментированный вызов HTML.Partial работает до некоторой точки, но когда он загружает этот Partial (пользовательский), который имеет несколько моделей в своей содержащей модели, ... эти другие модели становятся нулевыми, и его итерация по ним завершается сбоем.( Это частичное находится под первым блоком кода. ) Если я попытаюсь загрузить его из вызова действия, то функция JQuery ("$ # tabs"). Tabs вылетает с ".tabs" не определено

TIA

Код:

<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Tabs - Content via Ajax</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
    $(function ()
    {
        $("#tabs").tabs({
            beforeLoad: function (event, ui)
            {
                ui.jqXHR.fail(function ()
                {
                    ui.panel.html(
                        "Couldn't load this tab. We'll try to fix this as soon as possible. " +
                        "If this wouldn't be a demo.");
                });
            }
        });
    });
</script>

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Person Detail</a></li>
        <li><a href="#tabs-2">Addresses</a></li>
        <li><a href="#tabs-3">Role Detail</a></li>
        <li><a href="#tabs-4">User Detail</a></li>
    </ul>

    <div id="tabs-1">
        @*@Html.Partial("~/Views/Person/Index.cshtml")*@
    </div>

    <div id="tabs-2">
        @*@Html.Partial("~/Views/Address/Index.cshtml")*@
    </div>

    <div id="tabs-3">
        @Html.Partial("~/Views/IdentityRole/List.cshtml", new List<Catalyst.Shared.IdentityRole>())
    </div>

    <div id="tabs-4">
        @Html.Action("List", "User");

        @*@Html.Partial("~/Views/User/List.cshtml", new Catalyst.Mvc.IdentityUserPersonViewModel())*@


    </div>
</div>

Частичное, которое я хочу загрузить, но нуждается в данных,который, я думаю, сработал бы, если бы я вызвал Действие вместо вызова Частичного.

@model Catalyst.Mvc.IdentityUserPersonViewModel

@{
    ViewBag.User = "List";
 }


<div class="panel panel-default" style="width:1400px !important;text-align:center ">
<div class="panel-heading">
    <h3>Users</h3>
</div>
<div class="panel-body">
    <div style="text-align:right;">@Html.ActionLink("Add", "Create", null, new { @class = "btn btn-default" })</div>

    <table class="table table-bordered table-hover">
        <thead>
            <tr>
                <th>
                    UserName
                </th>
                <th>
                    Password
                </th>
                <th>
                    Title
                    @*@Html.DisplayNameFor(model => model.)*@
                </th>
                <th>
                    FirstName
                    @*@Html.DisplayNameFor(model => model.)*@
                </th>
                <th>
                    LastName
                </th>

                <th>
                    PhoneNumber
                </th>
                <th>
                    Email
                </th>
                <th>
                    Company and Branch
                </th>

                <th></th>
                <th></th>
            </tr>
        </thead>

        @for (var i = 0; i < Model.identityUsers.Count(); i++)
        {
        <tr>
            <td>
                <a href="@Url.Action("Edit", "User" , new {id=Model.UserPersons[i].UserPersonId})">
                    @Html.DisplayFor(x => Model.identityUsers[i].UserName)
                </a>
            </td>
            <td>
                <a href="@Url.Action("Edit", "User" , new {id=Model.UserPersons[i].UserPersonId})">
                    @Html.EditorFor(x => Model.identityUsers[i].PasswordHash, new { htmlAttributes = new { @class = "form-control", placeholder = "Password", Type = "password" } })
                </a>
            </td>

            <td>
                <a href="@Url.Action("Edit", "User" , new {id=Model.UserPersons[i].UserPersonId})">
                    @Html.DisplayFor(x => Model.UserPersons[i].Title)
                </a>
            </td>
            <td>
                <a href="@Url.Action("Edit", "User" , new {id=Model.UserPersons[i].UserPersonId})">
                    @Html.DisplayFor(x => Model.UserPersons[i].Name)
                </a>
            </td>
            <td>
                <a href="@Url.Action("Edit", "User" , new {id=Model.UserPersons[i].UserPersonId})">
                    @Html.DisplayFor(x => Model.UserPersons[i].Surname)
                </a>
            <td>
                @*<a href="@Url.Action("Edit", "User" , new {id=Model.identityUsers[i].Id})">
                    @Html.DisplayFor(x => Model.identityUsers[i].Email)
                </a>*@
            </td>
            <td>
                @*<a href="@Url.Action("Edit", "User" , new {id=Model.identityUsers[i].Id})">
                    @Html.DisplayFor(x => Model.identityUsers[i].PhoneNumber)
                </a>*@
            </td>

            <td>
                @*<a href="@Url.Action("Edit", "User" , new {id=item.ID})">
                    @Html.DisplayFor(x => item.PhoneNumber)
                </a>*@
            </td>

            <td>
                @Html.ActionLink("Edit", "Edit", new { id = 
Model.identityUsers[i].Id })
            </td>
            <td>
                @Html.ActionLink("Delete", "Delete", new { id = 
Model.identityUsers[i].Id })
            </td>
        </tr>
        }

    </table>

</div>

Контроллер вида, который я не могу загрузить

   public class UserController : Controller
{
    private IdentityUserBo identityUserBo;
    private PersonBo personBo;
    private IdentityUserPersonBo identityuser_personBo;

    IdentityUserPersonViewModel model = new IdentityUserPersonViewModel();

    public UserController(IdentityUserBo boIdentityUser, PersonBo boPerson, IdentityUserPersonBo boIdentityUserPerson )
    {
        this.identityUserBo = boIdentityUser ?? throw new ArgumentNullException("boIdentityUser");
        this.personBo = boPerson ?? throw new ArgumentNullException("boPerson");
        this.identityuser_personBo = boIdentityUserPerson ?? throw new ArgumentNullException("boIdentityUserPerson");
    }

    public ActionResult Index()
    {
        return RedirectToAction("List");
    }

    public ActionResult List()
    {
        ExBool result = null;
        IdentityUserPersonViewModel userPersonViewModel = new IdentityUserPersonViewModel();

        result = this.identityUserBo.List(out List<IdentityUser> identityUsers);

        if (!result.Success) throw new Exception(result.Messages);
        if (identityUsers == null) throw new Exception("Could not load IdentityUsers");

        // Ideally see detail eg  branch and tel and email from their respective tables
        userPersonViewModel.identityUsers = identityUsers;

        //Get the Persons, match these via Person.Id -> IdentityUserPerson.FKPersonId + IdentityUserPerson.FKUserId -> IdentityUser.ID
        List<Person> persons = null;
        result = this.personBo.List(out persons);

        //IdentityUserPersonViewModel viewModel = new IdentityUserPersonViewModel();
        userPersonViewModel.persons = persons;

        // Get the IdentityUserPersons 
        List<IdentityUserPerson> identityUserPersons = null;
        result = this.identityuser_personBo.List(out identityUserPersons);

        IdentityUserPerson UPRec = new IdentityUserPerson();
        Person PRec = new Person();
        userPersonViewModel.UserPersons = new List<UserPerson>();

        foreach (IdentityUser rec in userPersonViewModel.identityUsers)
        {
            UPRec = identityUserPersons.Find(x => x.FKUserID == rec.Id);
            if (UPRec != null)
            {
                //UserId, UserPersonId, + Person.Id + Person.Name + Person.Surname
                PRec = persons.Find(y => y.ID == UPRec.FKPersonID);

                UserPerson UsrPers = new UserPerson();
                UsrPers.UserId = rec.Id;
                UsrPers.UserPerson_FKPersonId = UPRec.FKPersonID;
                UsrPers.UserPerson_FKUserId = UPRec.FKUserID;
                UsrPers.Name = PRec.FirstName;
                UsrPers.Surname = PRec.LastName;
                UsrPers.Title = PRec.TitleCode;

                userPersonViewModel.UserPersons.Add(UsrPers);
            }
            else
            {
                UserPerson UsrPers = new UserPerson();
                userPersonViewModel.UserPersons.Add(UsrPers);
            }
        }

        return View(userPersonViewModel);
    }

1 Ответ

0 голосов
/ 20 декабря 2018

Проверьте вашу консоль, какую ошибку вы получили.

, а также измените ее в tab4

@{
        @Html.Partial("List", new Catalyst.Mvc.IdentityUserPersonViewModel())
    }
...