DmitryEfimenko / TwitterBootstrapMvc

Fluent implementation of ASP.NET-MVC HTML helpers for Twitter Bootstrap.
Apache License 2.0
223 stars 79 forks source link

Missing functions for BootstrapAlert class ? #422

Closed markusgud closed 8 years ago

markusgud commented 8 years ago

Hi,

I noticed that I can not always set Alert Style on an Alert. If I do this: @*@if (!string.IsNullOrEmpty(ViewBag.ReportMessage)) { @Html.Bootstrap().Alert(ViewBag.ReportMessage).Style(AlertColor.Success) }

I get this exception, since Style does not seem to exist on the class BootstrapAlert (whereas is does on class Alert):

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'TwitterBootstrapMVC.Controls.BootstrapAlert' does not contain a definition for 'Style

This, however, works fine: `@if (!string.IsNullOrEmpty(ViewBag.ReportMessage)) { using (Html.Bootstrap().Begin(new Alert().Style(AlertColor.Success))) {

@ViewBag.ReportMessage

        }
    }`

Should the former also be possible?

DmitryEfimenko commented 8 years ago

I get that same error message when ViewBag.ReportMessage is null Otherwise it works

markusgud commented 8 years ago

Strange. I have this view.

@using xxxx.Web.ViewModels
@using TwitterBootstrap3
@using TwitterBootstrapMVC

@model FormViewModel
@{
    ViewBag.Title = "Register";
    Layout = "../Shared/_Layout.cshtml";
}

@using (var f = Html.Bootstrap().Begin(new Form().Type(FormType.Horizontal))) {
    <div class="container">

        @if (!string.IsNullOrEmpty(ViewBag.ReportMessage))
        {
            @Html.Bootstrap().Alert(ViewBag.ReportMessage).Style(AlertColor.Success)
        }

       code using "f" 
}

I have in web.config system.web/pages/namespaces the following: <add namespace="TwitterBootstrapMVC" /> <add namespace="TwitterBootstrap3" />

I am referencing in the project TwitterBootstrapMVC5 version 3.17.0.0.

ViewBag.ReportMessage is not null in my case. Auto-type does not show "Style" after typing Html.Bootstrap().Alert(ViewBag.ReportMessage), the returned class is of type BootstrapAlert (not Alert).

DmitryEfimenko commented 8 years ago

the way I originally tested it was just switching ViewBag.ReportMessage with a hard coded string. The actual problem is due to the dynamic nature of ViewBag. Do this:

@Html.Bootstrap().Alert((string)ViewBag.ReportMessage).Style(AlertColor.Success)
markusgud commented 8 years ago

Thank you for the quick response. Interesting issue.

DmitryEfimenko commented 8 years ago

glad to help.