ASP.NET MVC 4 jQuery自动完成功能无法使用Razor [英] ASP.NET MVC 4 Jquery autocomplete not working using Razor
问题描述
我刚刚制作了一个ASP.NET MVC4内联网Web应用程序.我没有对默认代码进行太多更改.但是自动完成功能对我不起作用.当我说这对我不起作用时,意味着它显示了字段和CSS外观.但是像移动这样的功能不起作用.这是我的代码:
_Layout.cshtml
Hi I just made an ASP.NET MVC4 Intranet Web Application. I haven''t changed the code much from what the default was. But the autocomplete function does not work for me. When I mean it doesn''t work for me, meaning that it shows the fields and the css looking stuff. But the functionality like moving does not work. Here is my code:
_Layout.cshtml
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - FMCS Historical Data</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../Content/themes/cupertino/jquery.ui.all.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery-ui-1.8.11.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.11.js" type="text/javascript"></script>
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/themes/base/css", "~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
Index.cshtml
Index.cshtml
<pre lang="HTML">
<script type="text/javascript">
$(document).ready(function () {
$("#TagInfo").autocomplete(''@Url.Action("TagInfo","TagAutoComplete")'', {
minChars: 3
});
});
</script>
<ol class="round">
<li class="one">
<h5>class one header</h5>
class one text
<label for="TagInfo">
Tag:</label>
<input id="TagInfo" />
</li>
<li class="two">
<h5>
class two header</h5>
class two text </li>
<li class="three">
<h5>
class three header</h5>
class three text </li>
</ol>
TagAutoCompleteController
TagAutoCompleteController
public class TagAutoCompleteController : Controller
{
// This is the source link
// GET: /TagAutoComplete/
public ActionResult TagInfo(string searchstring)
{
TagDataDataContext dataContext = new TagDataDataContext();
var tagdata = (from t in dataContext.TagDatas
where t.TAG_NAME.Contains(searchstring)
select t.TAG_NAME).Distinct().Take(10);
string content = string.Join<string>("\n",tagdata);
return Content(content);
}
}
请帮帮我吗?
我只是添加了sortable,它是不可移动的.怎么了?
Please help me?
I just added sortable and it is not moveable. What is wrong?
<ul id="sortable">
<li class="ui-state-default">
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<div>1</div>
</li>
<li class="ui-state-default">
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<div>2</div>
</li>
<li class="ui-state-default">
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<div>3</div>
</li>
</ul>
推荐答案
(document).ready(function(){
(document).ready(function () {
(#TagInfo").autocomplete(' '@ Url.Action("TagInfo","TagAutoComplete"),{ minChars:3 }); }); </script> < ol class ="round"> < li class ="one"> < h5>第一个标头</h5> 一级课文 < label for ="TagInfo"> 标签:</label> < input id ="TagInfo"/> </li> < li class ="two"> < h5> 二类报头</h5> 第二类文字</li> < li class ="three"> < h5> 三类标头</h5> 第三类文字</li> </ol>
("#TagInfo").autocomplete(''@Url.Action("TagInfo","TagAutoComplete")'', { minChars: 3 }); }); </script> <ol class="round"> <li class="one"> <h5>class one header</h5> class one text <label for="TagInfo"> Tag:</label> <input id="TagInfo" /> </li> <li class="two"> <h5> class two header</h5> class two text </li> <li class="three"> <h5> class three header</h5> class three text </li> </ol>
TagAutoCompleteController
TagAutoCompleteController
public class TagAutoCompleteController : Controller
{
// This is the source link
// GET: /TagAutoComplete/
public ActionResult TagInfo(string searchstring)
{
TagDataDataContext dataContext = new TagDataDataContext();
var tagdata = (from t in dataContext.TagDatas
where t.TAG_NAME.Contains(searchstring)
select t.TAG_NAME).Distinct().Take(10);
string content = string.Join<string>("\n",tagdata);
return Content(content);
}
}
请帮帮我吗?
我只是添加了sortable,它是不可移动的.怎么了?
Please help me?
I just added sortable and it is not moveable. What is wrong?
<ul id="sortable">
<li class="ui-state-default">
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<div>1</div>
</li>
<li class="ui-state-default">
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<div>2</div>
</li>
<li class="ui-state-default">
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<div>3</div>
</li>
</ul>
我建议将其改回并进行测试,直到它再次起作用为止,那么您肯定会知道的. AJAX方法称为吗?在浏览器中可以正确显示吗?
I suggest changing things back and testing until it works again, then you''ll know for sure. Is the AJAX method called ? Is it rendered properly in the browser ?
这篇关于ASP.NET MVC 4 jQuery自动完成功能无法使用Razor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!