daveaglick / FluentBootstrap

Provides extensions, helper classes, model binding, and other goodies to help you use the Bootstrap CSS framework from .NET code.
http://www.fluentbootstrap.com
MIT License
200 stars 76 forks source link

AddStaticClass is ambiguous between FormExtensions and MvcFormExtensions #71

Closed fairking closed 7 years ago

fairking commented 7 years ago

I receive an error in following razor: @(Html.Bootstrap() .FormGroup() .AddChild(Html.Bootstrap().ControlLabel(x => x.H_TestDisplayStringValue).SetMd(4)) .AddChild(Html.Bootstrap().FormControl().AddStaticClass().SetMd(7) .AddContent(Html.DisplayFor(x => x.H_TestDisplayStringValue)) ) .AddChild(Html.Bootstrap().BadgeTooltip("Test Display").SetPullRight()) )

Message:

The call is ambiguous between the following methods or properties: 'FluentBootstrap.FormExtensions.AddStaticClass(FluentBootstrap.ComponentBuilder<TConfig, FluentBootstrap.Forms.FormControl>, bool)' and 'FluentBootstrap.MvcFormExtensions.AddStaticClass<TModel, TFormControlFor>(FluentBootstrap.ComponentBuilder<FluentBootstrap.Mvc.MvcBootstrapConfig, TFormControlFor>, bool)'

How can resolve the conflict of namespaces?

Thanks.

daveaglick commented 7 years ago

Try specifying the generic type parameters of the AddStaticClass() method like this (where ViewModel is whatever your model type for the view is):

@(Html.Bootstrap() .FormGroup() .AddChild(Html.Bootstrap().ControlLabel(x => x.H_TestDisplayStringValue).SetMd(4)) .AddChild(Html.Bootstrap().FormControl().AddStaticClass<MvcBootstrapConfig<ViewModel>>().SetMd(7) .AddContent(Html.DisplayFor(x => x.H_TestDisplayStringValue)) ) .AddChild(Html.Bootstrap().BadgeTooltip("Test Display").SetPullRight()) )

Getting rid of these ambiguous extension method resolution errors was a big problem a while back. I was able to squash almost all of them, but in complicated cases like this you sometimes have to give it a little hint.

Please reopen this issue if it looks like this suggestion doesn't work for you.