Cannot convert instance from System.Web.Mvc.HtmlHelper<dynamic> to ServiceStack.Html.HtmlHelper

StackOverflow https://stackoverflow.com/questions/23252666

  •  08-07-2023
  •  | 
  •  

سؤال

CS1928: 'System.Web.Mvc.HtmlHelper<dynamic>' does not contain a definition for 'RenderCssBundle' and the best extension method overload 'ServiceStack.Html.Bundler.RenderCssBundle(ServiceStack.Html.HtmlHelper, string, ServiceStack.Html.BundleOptions, string)' has some invalid arguments

@Html.RenderCssBundle("~/Content/app.css.bundle", BundleOptions.MinifiedAndCombined)

Did a default install of bundler over a servicestack, angular, MVC5.1 project.

Not sure why I'm getting this error, I did not modify bundle.cs

هل كانت مفيدة؟

المحلول

Hmm... looks like it's the Html extension methods conflicting: System.Web.Mvc.HtmlHelper vs ServiceStack.Html.HtmlHelper

They overlap and generally play nice but you may need to specify the fully qualified name... now I'd normally suggest this:

@ServiceStack.Html.HtmlHelper

However, bundler is not located within HtmlHelper. It's in a separate Bundle.cs file that happens to reside within the ServiceStack.Html namespace. So what you really want is this:

@ServiceStack.Html.Bundler.RenderCssBundle()

As a final check, you may want to make sure you reference ServiceStack.Html in your web.config or add a @using ServiceStack.Html at the top of your view. Here is where the reference goes in your web.config:

<system.web.webPages.razor>
    <host stuff="..." />
        <pages stuff="...">
            <namespaces>
                <!-- ... -->

                <add namespace="ServiceStack.Html" />

                <!-- ... -->
            </namespaces>
        </pages>
    </host>
</system.web.webPages.razor>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top