0

我有部分视图并且呈现指定的局部视图 - _GlobalPartialView。我_GlobalPartialView.cshtml的 部分部分视图中的自举警告

<div class="alert alert-success"> 
    <button type="button" class="close" data-dismiss="alert">&times;</button> 
    <strong>@result.Message</strong> 
</div> 

我PartialView:

@Html.Partial(T4.Shared.Views._GlobalMessagesPartial) 

在PartialView消息显示是这样的: enter image description here

上查看这样的: enter image description here

在视图上,我可以关闭警报框,但不是部分视图。为什么?如何解决它?

回答

0

所以这是相当老了,但我需要这样的事情,所以我决定后我的解决方案。

这是我的局部视图:

@* Message Box *@ 
@if (ViewBag.AlertMessage != null) 
{ 
<div class="col-sm-12"> 

    @if (ViewBag.AlertDismissable == true) 
    { 
     <div class="alert alert-dismissible @ViewBag.AlertType" role="alert"> 
      <button type="button" class="close" data-dismiss="alert" aria-label="Close"> 
       <span aria-hidden="true">&times;</span> 
      </button> 
      @ViewBag.AlertMessage 
     </div> 
    } 
    else 
    { 
     <div class="alert @ViewBag.AlertType" role="alert">@ViewBag.AlertMessage</div> 
    } 

    @*<div class="alert alert-success" role="alert">@ViewBag.Message</div>*@ 

</div> 

}

我有我的基类中的一些实用程序来设置ViewBag:

public void SetBSViewBagAlert(bsAlertType alerttype, string message) 
    { 
     SetBSViewBagAlert(alerttype, message, false); 
    } 

    public void SetBSViewBagAlert(bsAlertType alerttype, string message, bool dismissable) 
    { 
     // Translate from enum to constant to avoid typos... 
     switch (alerttype) 
     { 
      case bsAlertType.success: 
       ViewBag.AlertType = ALERT_SUCCESS; 
       break; 
      case bsAlertType.info: 
       ViewBag.AlertType = ALERT_INFO; 
       break; 
      case bsAlertType.warning: 
       ViewBag.AlertType = ALERT_WARNING; 
       break; 
      case bsAlertType.danger: 
       ViewBag.AlertType = ALERT_DANGER; 
       break; 
      default: 
       ViewBag.AlertType = ALERT_INFO; 
       break; 
     } 

     ViewBag.AlertDismissable = dismissable; 
     ViewBag.AlertMessage = message; 
    } 

一旦我知道我有错误我从控制器设置消息:

SetBSViewBagAlert(bsAlertType.warning, ModelStateErrorsString(), true); 

这是在视图所需要的只是行:

@Html.Partial("_AlertBoxPartial") 

我仍在调整各地与此有关。如果我进行更改,我会发布更新。