如何在ASP.NET Core 2.1中使用自动完成输入引发模式

克里斯托弗·安比亚多

我需要在ASP-NET Core 2.1的模态中实现JQuery自动完成功能

模态

问题是它什么也没显示,为什么我会出现这种现象?

我附上我的代码:

    <html>
    <head>
        <meta http-equiv="content-type" content="text/html" charset="utf-8" />
    
        <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
        @*<link rel="stylesheet" href="/resources/demos/style.css">*@
        <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    
        <script>
            jQuery(document).ready(function ($) {
                    $("#txtSearch").autocomplete({
                        source: '@Url.Action("BuscarProducto")'
                    });
                });
        </script>
    
    </head>
    <body>
    
        <div style="margin-top:60px; margin-bottom:20px" align="right">
    
            <a href="#" class="btn btn-primary" data-toggle="modal" data-target="#agregarProducto"><i class="glyphicon glyphicon-plus"></i> Agregar Material </a>
    
       
    </body>
    </html>

<!--MODAL AGREGAR PRODUCTO-->
<div class="modal fade" id="agregarProducto">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Agregar Material</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="alert alert-dismissible alert-info">
                    <button type="button" class="close" data-dismiss="alert">&times;</button>
                    <strong>Tener en cuenta!</strong> <a> para agregar más de una unidad habilite</a><strong> agregar cantidad.</strong>
                </div>
                <form id="myForm">
                    <label>Producto</label> &nbsp;&nbsp;
                    <input type="text" class="form-control" name="searchTerm" id="txtSearch" />
                    <br />

                    <br />
                    <label>Agregar Cantidad</label> &nbsp;&nbsp;
                    <input type="text" class="form-control" name="cantidad" id="idcantidad" />

                </form>
            </div>
            <div class="modal-footer">
                <input type="button" value="Agregar Material" class="btn btn-primary" id="btnSubmit" />
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
            </div>
        </div>
    </div>
</div>

如您所见...我的Json方法返回从模态输入的建议

控制者

但是由于某种原因,它没有在模式中指示的输入中显示建议,这是怎么回事?我忘了做什么?对我有帮助吗?

瑞娜

您可以使用apendTo选项,如下所示:

更改您的HTML:

<form id="myForm">
    <label>Producto</label> &nbsp;&nbsp;
    <input type="text" class="form-control" name="searchTerm" id="txtSearch" />
        @*add this div*@

    <div id="Searchdata"></div>

    <br />
    <br />
    <label>Agregar Cantidad</label> &nbsp;&nbsp;
    <input type="text" class="form-control" name="cantidad" id="idcantidad" />
</form>

更改您的jQuery:

jQuery(document).ready(function ($) {
    $("#txtSearch").autocomplete({
        source: '@Url.Action("BuscarProducto")'
    });
    $("#txtSearch").autocomplete("option", "appendTo", "#Searchdata");

});

结果: 在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Asp.net Core 2-如何在Asp.net Core 2.0中使用ServiceLocator

如何在ASP.NET Core 2中引发ForbiddenException,而不是使用AccessDeniedPath

如何在ASP.net Core 2中使用Windsor IoC

如何在 Jetbrains Rider 中為 ASP.NET CORE 2 設置 XUnit 測試?

如何在ASP.NET Core 2中对Facebook Web API进行身份验证

如何在发布中包含asp.net Core 2依赖项

如何在ASP.NET Core RC2中制作Websocket服务器?

如何在TFS中构建ASP.NET Core 2应用

如何在ASP.NET Core 2.0中为EFCore 2配置SQL的日志记录

如何在ASP.NET Core 2中添加身份验证Cookie超时

如何在ASP.NET Core 2中为Steam配置OpenID Connect?

如何在ASP.NET Core 2中更改CreatedAtAction的路由格式?

如何在ASP.NET Core 2.x中以会话状态存储和检索对象?

如何在ASP.net Core 2中创建动态API

如何在asp.net core中实现经典的webapi 2路由

如何在ASP.NET Core 3.1中使用自动生成的刷新令牌?

如何在ASP.NET Core中使用Bootstrap 4

如何在ASP.NET Core应用中使用HttpClient

如何在 ASP.Net Core 3 中使用 UseNodeModules?

如何在ASP.NET Core中使用jquery

如何在ASP.NET Core中使用SqlClient?

如何在ASP.NET Core中使用区域

如何在ASP.NET Core中使用npm

如何在 Asp.Net Core 中使用 Ninject?

如何在 ASP.NET Core 中使用 API?

如何在 ASP.NET Core 中使用异步“ForEach”?

如何在 ASP.NET Core 2 MVC 中使用依赖注入设置单元可测试模型验证?

如何在 Visual Studio Team Services (VSTS) 中构建 ASP.NET Core 2 RC2 项目?

如何在Asp.net Core rc1中的静态方法中使用DI