MVC自动完成文本框相关问题! [英] MVC Auto completion textbox related issue!
本文介绍了MVC自动完成文本框相关问题!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,使用javasript我设法做了一个自动完成文本框。它在测试应用程序中工作,但是当我将它用于现有应用程序时,控制器方法总是获得空值。我猜javascript函数返回Null值。有没有人对此有所了解?在此先感谢!!!
代码:
{
//在Homecontroller
public JsonResult AutocompleteSuggestions(string serchtext)
{
var suggestions = selectEmployees.getEmployeeSuggestedNumbers(serchtext);
返回Json(建议,JsonRequestBehavior.AllowGet);
}
// searchtext从View
< script src =<%:Url.Content(〜/ Scripts / jquery)获取Null值-1.4.4.min.js )%> 中类型= 文本/ JavaScript的 >< /脚本>
< script src =<%:Url.Content(〜/ Scripts / jquery-ui.min.js)%>类型= 文本/ JavaScript的 >< /脚本>
//在index.aspx
< h3 class =searchlabel>搜索< / h3>
< form1 runat =serveraction =method =post>
< input id =searchTermname =searchTermtype =text/>& nbsp;
< script type =text / javascript>
$(function(){
$(#searchTerm)。autocomplete({
source:/ Home / AutocompleteSuggestions,
minLength:1,
select:function(event,ol){
if(ol.item){
$(#searchTerm)。val(ol.item.value);
$(form1 ).submit();
}
}
});
});
< / script>
<% - <%Html.RenderPartial(〜/ Views / Home / Search.ascx); %GT; - %>
解决方案
(function(){
(#searchTerm ).autocomplete({
source:/ Home / AutocompleteSuggestions,
minLength:1,
select:function(event,ol){
if(ol.item){
( #SEARCHTERM)VAL(ol.item.value);
Hi everyone, using javasript I managed to do an auto completion textbox. It worked in the testing app, but when I used it for the existing application, the controller method is always getting a null value. I guess the javascript function is returning a Null value. Does anyone have an idea on this? Thanks in advance!!!
code :
{ //in the Homecontroller public JsonResult AutocompleteSuggestions(string serchtext) { var suggestions = selectEmployees.getEmployeeSuggestedNumbers(serchtext); return Json(suggestions, JsonRequestBehavior.AllowGet); } //searchtext getting Null values from the View <script src="<%: Url.Content("~/Scripts/jquery-1.4.4.min.js")%>" type="text/javascript"></script> <script src="<%: Url.Content("~/Scripts/jquery-ui.min.js")%>" type="text/javascript"></script> //in the index.aspx <h3 class="searchlabel">Search</h3> <form1 runat="server" action = "" method="post"> <input id="searchTerm" name="searchTerm" type="text" /> <script type="text/javascript"> $(function () { $("#searchTerm").autocomplete({ source: "/Home/AutocompleteSuggestions", minLength: 1, select: function (event, ol) { if (ol.item) { $("#searchTerm").val(ol.item.value); $("form1").submit(); } } }); }); </script> <%-- <% Html.RenderPartial("~/Views/Home/Search.ascx"); %> --%>
解决方案
(function () {
("#searchTerm").autocomplete({ source: "/Home/AutocompleteSuggestions", minLength: 1, select: function (event, ol) { if (ol.item) {
("#searchTerm").val(ol.item.value);
这篇关于MVC自动完成文本框相关问题!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文