Closed markusgud closed 8 years ago
I get that same error message when ViewBag.ReportMessage
is null
Otherwise it works
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).
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)
Thank you for the quick response. Interesting issue.
glad to help.
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?