2017-04-20 67 views
1

您好我想创建一个文件上传控制并使用bootstrap fileupload呈现它。控制不呈现在asp.net上的引导文件上传mvc

我使用Visual Studio 2017年v 15.1

我从加入的NuGet引导-的FileInput(V 4.3.9)

代码:

@model RecsMVC.Models.DadesKoboViewModel 
@{ 
    ViewBag.Title = "Dades KoboToolbox"; 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
} 
@using (Html.BeginForm()) 
{ 
    <div class="form-horizontal"> 
     <input id="input_id" name="input_id" type="file" class="file" /> 
    </div> 
} 

当我设置类,自动完成没有找到文件作为合适的类,但我可以看到几个bootstrap文件输入类(文件操作,文件拖放区...)

谢谢你,并为我的坏engl抱歉十岁上下

+0

你指的是'bootstrap-fileinput'包吗?因为我似乎没有看到'bootstrap-fileupload'。 –

+0

Ooops,蝙蝠打字......我刚纠正它。谢谢! – csk

回答

0

确保适当的依赖引用

因为你的类被渲染,听起来根本就与你的Javascript和CSS具体提及的问题没有被发现。

考虑确保您的相关bootstrap-fileinput插件文件被正确引用和出现后的任何项目,他们可能依赖于(如jQuery的,引导等):

<!-- jQuery --> 
<script src="~/lib/jquery/dist/jquery.js"></script> 

<!-- Bootstrap --> 
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script> 
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" /> 

<!-- Bootstrap-FileInput --> 
<script src="~/lib/bootstrap-fileinput/js/fileinput.min.js"></script> 
<link href="~/lib/bootstrap-fileinput/css/fileinput.min.css" rel="stylesheet" /> 

@using (Html.BeginForm()) 
{ 
    <div class="form-horizontal"> 
     <input id="input_id" name="input_id" type="file" class="file" /> 
    </div> 
} 

如果这些正确加载,你应该看到你的应用类如预期:

enter image description here

如果有你需要申请任何特定的初始化代码,你可以添加额外的<script>标签和明确的目标元素,如下图所示:

$(":file").fileinput({'showUpload':false, 'previewFileType':'any'}); 

如果你有问题,使用脚本部分

值得一提的是,如果你拥有jQuery和引导您_Layout.cshtml页面内定义,那么你“大概会想用一个部分,以确保这些被引用这些依赖,以及:

<!-- Place this at the end of your _Layout.csthml after your existing scripts --> 
@RenderSection("scripts", required: false) 

<!-- Place this within your partial view/view --> 
@section scripts { 
    <script src="~/lib/bootstrap-fileinput/js/fileinput.min.js"></script> 
} 

氏s将允许您更精细地控制,其中如果您在脚本内的子视图内引用脚本,则会呈现脚本。

考虑使用不同的软件包管理器

值得一提的是,的NuGet最近搬走(或试图)从客户端软件包赞成使用另一种包管理器,如故宫,凉亭等。你可能会发现使用其中的一种来拉动你的包比Nuget更容易。

0

原始问题与自动完成有关。以下是在Visual Studio 2017中使用Bootstrap 4自动完成工作的解决方案。

看来,Visual Studio从wwwroot \ lib \ bootstrap \ dist中的文件中获取它的自动完成数据。刷新这些文件有下列步骤操作:

  • 从项目菜单中选择“管理鲍尔包”
  • 查找引导,验证版本,然后单击安装
  • 删除的内容: 的wwwroot \ LIB \引导\ DIST
  • 复制的内容: bower_components \引导\ DIST 到: 的wwwroot \ LIB \引导\ DIST

您还必须更改代码中的任何引用以指向新版本。