如何在模态的部分视图中包含 Jquery 函数
我有一个 jquery 按钮单击方法,该方法在模态之外的视图中工作正常。在模态中加载部分视图时,uploadbtn 按钮单击方法不起作用
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<div class="form-group">
<div class="col-md-10">
<p>Upload one or more files using this form:</p>
<input type="file" id="files" name="files" multiple />
<input id="documentType" name="entity" value=@ViewData["entity"] hidden>
<input id="id" name="id" value=@Model hidden>
</div>
</div>
<div class="form-group">
<div class="col-md-10">
<input type="submit" id="upload" value="Upload" />
<button type="button" id="uploadbtn">Upload</button>
</div>
</div>
<script>
$(document).ready(function () {
$("#uploadbtn").click(function () {
console.log("came");
var documentType = $('#documentType').val();
var fileUpload = $("#files").get(0);
var files = fileUpload.files;
console.log(files);
});
});
</script>
有人可以告诉我应该做什么才能在模态中工作吗? 我正在从事 .net core 项目
I have a jquery button click method which works fine in views other than modals.uploadbtn button click method doesn't work when partial view is loaded in the modals
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<div class="form-group">
<div class="col-md-10">
<p>Upload one or more files using this form:</p>
<input type="file" id="files" name="files" multiple />
<input id="documentType" name="entity" value=@ViewData["entity"] hidden>
<input id="id" name="id" value=@Model hidden>
</div>
</div>
<div class="form-group">
<div class="col-md-10">
<input type="submit" id="upload" value="Upload" />
<button type="button" id="uploadbtn">Upload</button>
</div>
</div>
<script>
$(document).ready(function () {
$("#uploadbtn").click(function () {
console.log("came");
var documentType = $('#documentType').val();
var fileUpload = $("#files").get(0);
var files = fileUpload.files;
console.log(files);
});
});
</script>
Can someone tell me what I should do in order to get this working in the modals?
I am working in a .net core project
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新演示如下:
Controller.cs:我创建一个操作
BBB
来返回_FilePartialView
。在隐私视图中,我添加了一个上传文件的模式。
_FilePartialView.cshtml:
[注意]
我删除了Update Demo as below:
Controller.cs: I create an action
BBB
to return_FilePartialView
.In privacy view, I add a modal to upload file.
_FilePartialView.cshtml:
[Note]
I remove<script src="~/lib/jquery/dist/jquery.min.js"></script>