问题delimitir使用jQuery和MVC剃刀 [英] Problem with delimitir using jquery and mvc razor

查看:102
本文介绍了问题delimitir使用jQuery和MVC剃刀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能几个值相同的字段添加。我只能选择一个值,以后我输入; 或其它分隔符,我不能选择另一个。我希望它的工作方式与自动完成。

I can't add few values to the same field. I can select only one value, and after I input ,, ; or other delimiter character, I can't select another one. I want it to work similar to autocomplete.

我有jQuery的一个文本框的约束:

I have a textbox with jQuery bound:

<div class="editor-field">
    @Html.EditorFor(model => model.Name) @Html.ValidationMessageFor(model => model.Name)
</div>
<script type="text/javascript">
$(document).ready(function () {
    $("#Name").autocomplete('@Url.Action("TagName", "Tag")', {
        minChars: 1,
        delimiter: /(,|;)\s*/,
        onSelect: function(value, data){
            alert('You selected: ' + value + ', ' + data);
        }
    });
});
</script>

从我的控制器使用数据:

It uses data from my controller:

public ActionResult TagName(string q)
{
    var tags = new List<TagModel>
    {
        new TagModel {Name = "aaaa", NumberOfUse = "0"},
        new TagModel {Name = "mkoh", NumberOfUse = "1"},
        new TagModel {Name = "asdf", NumberOfUse = "2"},
        new TagModel {Name = "zxcv", NumberOfUse = "3"},
        new TagModel {Name = "qwer", NumberOfUse = "4"},
        new TagModel {Name = "tyui", NumberOfUse = "5"},
        new TagModel {Name = "asdf[", NumberOfUse = "6"},
        new TagModel {Name = "mnbv", NumberOfUse = "7"}
    };

    var tagNames = (from p in tags where p.Name.Contains(q) select p.Name).Distinct().Take(3);

    string content = string.Join<string>("\n", tagNames);
    return Content(content);
}

我使用这些脚本:

I'm using these scripts:

<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.autocomplete.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Scripts/jquery.autocomplete.css")" rel="stylesheet" type="text/css" />

有在萤火没有错误。有什么不对我的code?

There is no error in firebug. What is wrong with my code?

推荐答案

经历过这种问题,萤火虫。

Experienced this kind of problems with firebug.

我建议不信任Firebug的控制台
  直到它包含错误信息

I suggest to not trust Firebug console until it contains error messages

如果你的code未按照预期工作,和Firebug是不显示你那么任何错误消息是时候来检查你的网页在Chrome和清楚地看到这个异常没有控制台选项卡中进行处理,特别是当你使用AJAX

If your code is not working as expected, and firebug is not showing you any error messages then it's time to check your web page in chrome and see where exactly the exception is not handled within Console tab, specially when you're using ajax.

这篇关于问题delimitir使用jQuery和MVC剃刀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆