【问题标题】:Error trying to use module template and web.unified host sample尝试使用模块模板和 web.unified 主机示例时出错
【发布时间】:2020-11-07 12:53:36
【问题描述】:

我正在尝试基于模块模板执行 web.unified 宿主项目

  1. abp new sample.module -t module。 ABP CLI 版本 3.3.1
  2. 恢复:dotnet restore.Ok!
  3. 构建:dotnet build。好的!
  4. 在域 (member.cs) 中添加新实体并使用 AbpHelper.GUI 自动生成所有代码。正确完成!
  5. 使用 web.unified 添加迁移和更新数据库。完美!
  6. 运行 web.unified web 应用程序build run
  7. 使用浏览器打开应用(Chrome 更新)并导航到新菜单。
  8. 出现成员索引页面(来自模块 Web 项目)。导航和路线似乎很好。酷!
  9. 但是浏览器控制台显示错误:
Uncaught TypeError: Cannot read property 'member' of undefined
    at HTMLDocument.<anonymous> (index.js?_v=637403462413691892:5)
    at mightThrow (jquery.js?_v=637403457898237859:3534)
    at process (jquery.js?_v=637403457898237859:3602)
$(function () {

    var l = abp.localization.getResource('Membership');

    var service = sample.membership.members.member; //<-- ERROR HERE sample.module.members is the namespace of entity in the module.
    var createModal = new abp.ModalManager(abp.appPath + 'Membership/Members/Member/CreateModal');
    var editModal = new abp.ModalManager(abp.appPath + 'Membership/Members/Member/EditModal');
...

非常感谢您的意见

【问题讨论】:

    标签: abp


    【解决方案1】:

    我明白了!,问题是Auto API controllers。 使用 abp new sample.module -t module 创建的示例 Hosts/*.web.unified 项目没有为模块配置 Auto API 控制器。

    在您的 HostWebUnifiedModule.cs 中添加此部分。 重要提示:添加对您的模块应用程序项目的引用MembershipApplicationModule

    [DependsOn(MembershipApplicationModule)]
    public class HostWebUnifiedModule: AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            Configure<AbpAspNetCoreMvcOptions>(options =>
            {
                options
                    .ConventionalControllers            .Create(typeof(MemberhsipApplicationModule).Assembly);
            });
        }
    }
    

    您获得:

    1. 自动 API 控制器。太棒了!您可以使用 swagger 进行测试。
    2. javascript 库 (Dynamics JavaScript Library) 现在可以使用 API 正常工作。

    错误消失了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-26
      • 2020-11-20
      • 1970-01-01
      • 1970-01-01
      • 2012-03-09
      • 2013-02-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多