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") 

我仍在調整各地與此有關。如果我進行更改,我會發布更新。