【问题标题】:Failed to load resource: the server responded with a status of 500 (Internal Server Error) dynamic api加载资源失败:服务器响应状态为 500 (Internal Server Error) 动态 api
【发布时间】:2017-10-07 15:22:53
【问题描述】:

下载的最新(3.0)样板为零。

跟进 codeproject.com 上的任务创建器应用程序实现

我添加了简单实体(客户端)而不是任务。

任务的显示工作正常。但是,当我尝试添加新客户端时,动态 api 似乎不可用,并且出现以下错误:

客户端控制器:

`[AbpMvcAuthorize] 公共类 ClientsController : MyAppControllerBase { 私有只读 IClientAppService _clientService;

    public ClientsController(IClientAppService clientService)
    {
        _clientService = clientService;
    }

    public async Task<ViewResult> Index(GetAllClientsInput input)
    {
        var output = await _clientService.GetAll(input);
        var model = new Web.Models.Clients.IndexViewModel(output.Items);
        return View("Index", model);

    }

    public async Task Create(CreateClientInput input)
    {
        await _clientService.Create(input);
    }

    public async Task Delete(CreateClientInput input)
    {
        await _clientService.Create(input);
    }
}` 

Index.js:

(function() {
    $(function() {

        var _clientService = abp.services.app.client;
        var _$modal = $('#ClientCreateModal');
        var _$form = _$modal.find('form');

        _$form.validate();

        _$form.find('button[type="submit"]').click(function (e) {
            e.preventDefault();

            if (!_$form.valid()) {
                return;
            }

            var client = _$form.serializeFormToObject(); //serializeFormToObject is defined in main.js

            abp.ui.setBusy(_$modal);
            _clientService.create(client).done(function () {
                _$modal.modal('hide');
                location.reload(true); //reload page to see new user!
            }).always(function () {
                abp.ui.clearBusy(_$modal);
            });
        });

        _$modal.on('shown.bs.modal', function () {
            _$modal.find('input:not([type=hidden]):first').focus();
        });
    });
})();

索引.cshtml

@section scripts
{
    <environment names="Development">
        <script src="~/js/views/clients/Index.js" asp-append-version="true"></script>
    </environment>

    <environment names="Staging,Production">
        <script src="~/js/views/clients/Index.min.js" asp-append-version="true"></script>
    </environment>
}
<div class="row clearfix">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <div class="card">
            <div class="header">
                <h2>
                    @L("Clients")
                </h2>
                <ul class="header-dropdown m-r--5">
                    <li class="dropdown">
                        <a href="javascript:void(0);" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                            <i class="material-icons">more_vert</i>
                        </a>
                        <ul class="dropdown-menu pull-right">
                            <li><a href="javascript:void(0);" class=" waves-effect waves-block">Action</a></li>
                            <li><a href="javascript:void(0);" class=" waves-effect waves-block">Another action</a></li>
                            <li><a href="javascript:void(0);" class=" waves-effect waves-block">Something else here</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
            <div class="body table-responsive">
                <table class="table">
                    <thead>
                    <tr>
                        <th>@L("UserName")</th>
                        <th>@L("FullName")</th>
                        <th>@L("EmailAddress")</th>
                        <th>@L("IsActive")</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach (var user in Model.Clients)
                    {
                        <tr>
                            <td>@user.FirstName</td>
                            <td>@user.LastName</td>
                            <td>@user.Email</td>
                            <td>@user.Mobile</td>
                        </tr>
                    }
                    </tbody>
                </table>
                <button type="button" class="btn btn-primary btn-circle waves-effect waves-circle waves-float pull-right" data-toggle="modal" data-target="#ClientCreateModal">
                    <i class="material-icons">add</i>
                </button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="ClientCreateModal" tabindex="-1" role="dialog" aria-labelledby="ClientCreateModalLabel" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form name="userCreateForm" role="form" novalidate class="form-validation">
                <div class="modal-header">
                    <h4 class="modal-title">
                        <span>@L("CreateNewClient")</span>
                    </h4>
                </div>
                <div class="modal-body">
                    <div class="form-group form-float">
                        <div class="form-line">
                            <input class="form-control" type="text" name="FirstName" required maxlength="@AbpUserBase.MaxUserNameLength" minlength="2">
                            <label class="form-label">@L("FirstName")</label>
                        </div>
                    </div>
                    <div class="form-group form-float">
                        <div class="form-line">
                            <input type="text" name="LastName" class="form-control" required maxlength="@AbpUserBase.MaxNameLength">
                            <label class="form-label">@L("LastName")</label>
                        </div>
                    </div>
                    <div class="form-group form-float">
                        <div class="form-line">
                            <input type="text" name="Mobile" class="form-control" required maxlength="@AbpUserBase.MaxSurnameLength">
                            <label class="form-label">@L("Mobile")</label>
                        </div>
                    </div>
                    <div class="form-group form-float">
                        <div class="form-line">
                            <input type="email" name="Email" class="form-control" required maxlength="@AbpUserBase.MaxEmailAddressLength">
                            <label class="form-label">@L("Email")</label>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">@L("Cancel")</button>
                    <button type="submit" class="btn btn-primary waves-effect">@L("Save")</button>
                </div>
            </form>
        </div>
    </div>
</div>

客户服务:

[AbpAuthorize(PermissionNames.Pages_Tenants)]
public class ClientAppService : ApplicationService, IClientAppService
{
    private readonly IRepository<Client> _clientRepository;

    public ClientAppService(IRepository<Client> clientRepository)
    {
        _clientRepository = clientRepository;
    }

    public async Task<ListResultDto<ClientListDto>> GetAll(GetAllClientsInput input)
    {
        var clients = await _clientRepository
            .GetAll().ToListAsync<Client>();

        return new ListResultDto<ClientListDto>(
            ObjectMapper.Map<List<ClientListDto>>(clients));
    }

    public async Task Create(CreateClientInput input)
    {
        var task = ObjectMapper.Map<Client>(input);
        await _clientRepository.InsertAsync(task);
    }
}

服务器在创建操作上完全没有受到影响。

知道我错过了什么吗?

【问题讨论】:

  • 你能检查*.Web.Mvc\App_Data\Logs的错误日志吗?
  • 非常感谢。日志文件说明了很多。客户端实现 IMustHaveTenant。当我以主机用户身份登录时,错误提示“无法将 IMustHaveTenant 实体的 TenantId 设置为 0!”我希望我能看到该警告,而不是收到内部服务器错误!
  • 嗯,这是一个编程错误,不应该对客户端可见。

标签: aspnetboilerplate


【解决方案1】:

我认为对 IMustHaveTenant 接口存在误解。当您从 IMustHaveTenant 派生实体时,您不能在宿主环境中使用该实体。主机没有租户 ID。据我了解,客户属于租户。所以你需要做的是,从主机菜单中删除客户端页面。每当您想查看租户的客户时,只需使用模拟即可。

要显示/隐藏特定菜单项,您可以使用 requiredPermissionName。可以将权限配置为仅用于租户/主机/两者。因此,创建一个配置为供租户使用的新权限。在为客户页面创建新的 MenuItemDefinition 时设置该权限。就是这样!

读取 => https://aspnetboilerplate.com/Pages/Documents/Navigation?searchKey=navigation#registering-navigation-provider

【讨论】:

  • 不确定是否有一种简单的方法可以从主机菜单中删除菜单。我认为菜单是在房东和租户之间共享的。但是,保留菜单但删除禁用添加新客户端是有意义的。因为主机无论如何都应该能够访问和查看所有客户端列表。
  • 我使用 requiredPermissionName 属性更新了我的答案。这是您案件的重点。
猜你喜欢
  • 1970-01-01
  • 2017-11-14
  • 2016-06-29
  • 1970-01-01
  • 2017-06-25
  • 1970-01-01
  • 1970-01-01
  • 2014-04-10
  • 1970-01-01
相关资源
最近更新 更多