苦苦挣扎于Business Pack Alert组件

时间:2017-07-21 11:33:29

标签: dotvvm

我正在尝试为我们的应用程序制作一些动态逻辑,但<bp:Alert>组件并不想合作。

这是母版页面ViewModel:

public class AdminMasterPageViewModel : DotvvmViewModelBase
{
    public virtual AlertComponent AlertComponent { get; set; }
    public DotVVM.BusinessPack.Controls.AlertType AlertType { get; set; }

    public AdminMasterPageViewModel()
    {
    }

    public override Task Init()
    {
        InitAlertComponents();
        return base.Init();
    }

    private void InitAlertComponents()
    {
        AlertComponent = new AlertComponent
        {
            IsDisplayed = false,
            Text = "Default",
            Type = AlertComponent.Types.Info
        };

        AlertType = DotVVM.BusinessPack.Controls.AlertType.Info;
    }

}

这是MasterView中的dothtml:

    <%--MAIN CONTENT BY PLACEHOLDER--%>
    <div class="content-wrapper">

        <bp:Alert Type="{value: AlertType}"
                  IsDisplayed="{value: AlertComponent.IsDisplayed}"
                  AllowDismiss="true"
                  Text="{value: AlertComponent.Text}"
                  AutoHideTimeout="3" />

        <dot:ContentPlaceHolder ID="MainContent" />
    </div>

In&#34; Child&#34; ViewModel我有这个事件:

 public async void SaveUserRoleGroup()
    {
        UserRoleGroupDetailDTO.AppRoleForUserRoleGroupListDTOs = AppRoleListDTOs.Items.Where(i => i.IsAllowed = true).ToList();

        AlertComponent = await userRoleGroupDetailFacade.CreateUserRoleGroupAsync(UserRoleGroupDetailDTO);

    }

此组件的我的类表示符是:

 public class AlertComponent
{
    public bool IsDisplayed { get; set; }
    public string Text { get; set; }
    public Types Type { get; set; }
    public enum Types
    {
        Success, Info, Warning, Danger
    }
}

最后我的门面功能:

public async Task<AlertComponent> CreateUserRoleGroupAsync(UserRoleGroupDetailDTO dto)
    {
        using (var uow = unitOfWorkProvider.Create())
        {
            try
            {
                var userRoleGroup = Mapper.Map<UserRoleGroup>(dto);
                userRoleGroup.PortalSetting = portalSettingRepository.GetById(1);

                repository.Insert(userRoleGroup);

                await uow.CommitAsync();
            }
            catch (Exception e)
            {
                return new AlertComponent
                {
                    Text = "Error",
                    IsDisplayed = true,
                    Type = AlertComponent.Types.Danger
                };
            }
        }
        return new AlertComponent
        {
            Text = "Success",
            IsDisplayed = true,
            Type = AlertComponent.Types.Success
        };
    }

如您所见,我在SaveUserRoleGroup函数中设置AlertComponent,但在浏览器中没有任何反应。 我没有更改AlertType,但它没有关系,它仍然具有默认&#34; AlertType&#34;信息,我在MasterViewModel中设置。 那么为什么警报不显示而不起作用?

1 个答案:

答案 0 :(得分:0)

将Alert类型绑定到您在viewmodel Init中设置的AlertType属性。因此,当您稍后更改AlertComponent时,您没有设置AlertType。

或者你可以使用litle技巧

public AlertType AlertType => (AlertType)AlertComponent.Type;

我们应该将DotVVM.BusinessPack拆分为两个nuget包。一个是Core类型,一个是dotvvm依赖。