2017-10-07 202 views
0

下載最新(3.0)樣板爲零。加載資源失敗:服務器響應狀態爲500(內部服務器錯誤)動態api

跟進,而不是任務codeproject.com

我加入了簡單的實體(客戶端)的任務創建者的應用程序執行。

任務的顯示工作正常。然而,當我嘗試添加一個新的客戶端似乎動態API是不可用,我收到以下錯誤:

image ClientsController:

`[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(); 
     }); 
    }); 
})(); 

Index.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); 
    } 
} 

服務器不被打到在所有的創建行動。

任何想法我失蹤?

+0

您可以檢查錯誤日誌中'* .Web.Mvc \ App_Data文件\ Logs'? – aaron

+0

非常感謝。日誌文件告訴了很多。客戶端實現IMustHaveTenant。並且當我以主機用戶的身份登錄時,錯誤顯示「無法爲IMustHaveTenant實體將TenantId設置爲0!」我希望我能看到該警告,而不是發生內部服務器錯誤! – akd

+0

那麼,這是一個編程錯誤,客戶端不應該可見。 – aaron

回答

1

我認爲IMustHaveTenant界面存在誤解。當您從IMustHaveTenant派生實體時,您不能在主機環境中使用該實體。主機沒有租戶ID。據我瞭解,客戶屬於租戶。所以你必須做的是,從主機菜單中刪除客戶端頁面。每當你想看到租戶的客戶,只需使用模擬。

要顯示/隱藏特定菜單項,您可以使用requiredPermissionName。權限可以配置爲僅用於租戶/主機/兩者。因此,創建一個配置爲用於租戶的新權限。在爲客戶端頁面創建新的MenuItemDefinition時設置該權限。而已!

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

+0

不確定是否有簡單的方法從主機菜單中刪除菜單。我認爲菜單是在主機和租戶之間共享的。然而,保持菜單但刪除禁用添加新客戶端是有意義的。因爲主機應該能夠訪問並查看所有客戶端列表。 – akd

+0

我使用requiredPermissionName屬性更新了我的asnwer。這是你的情況的重要一點。 –

相關問題