简体   繁体   中英

MVC Package load (NuGet)

After installing the package with NuGet console (called bootstrap-table ), in packages.config I can see that the package is added but I cannot use it, nor the htmlhelpers that are coming with it.

I tried reinstalling the package, restarting VS2013 but it doesn't seem to help.

When I run the sample project from Simonray I can see the htmlhelpers, but his project doesn't use the package but a precompilled dll. Here is a screenshot from NuGet package manager, his and mine projects: http://prntscr.com/75gjar

Any advice?

In the web.config in your Views folder, you need to add the namespace. This is equivalent to adding a using statement in C#, add this last line:

<system.web.webPages.razor>
  <pages pageBaseType="System.Web.Mvc.WebViewPage">
    <namespaces>
      ...
      <add namespace="BootstrapTable.Web" />

Note that the example project you linked already has this line included here .

Here's how I got it to work. It would seem that the latest version of the package is slightly borked.

1) Firstly, install version 1.0.0 of the package into the project using the following command:

Install-Package bootstrap-table.mvc -Version 1.0.0

This correctly adds the reference to the BootstrapTable dll.

2) Now, run the Update-Package command like so:

Update-Package bootstrap-table.mvc

3) Updating the package unfortunately for some reason removes the Microsoft.AspNet.Mvc package. Sigh. So you should now re-add it by using the following command:

Install-Package Microsoft.AspNet.Mvc

4) Build your project.

5) The Html helpers for BootstrapTable are in the namespace System.Web.Mvc . This namespace should already be in the Web.config that is in the Views folder... but if not you should add it:

<configuration>
  <system.web.webPages.razor>
    ...
      <namespaces>
        <add namespace="System.Web.Mvc" />
        ...
      </namespaces>
    </pages>
  </system.web.webPages.razor>
</configuration>

6) Everything should now work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM