Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC:新手自动完成_C#_Jquery_Asp.net Mvc_Autocomplete - Fatal编程技术网

C# MVC:新手自动完成

C# MVC:新手自动完成,c#,jquery,asp.net-mvc,autocomplete,C#,Jquery,Asp.net Mvc,Autocomplete,我正在尝试在我的Asp.NETMVC应用程序中创建一个自动完成框。 这就是我到现在为止所做的 我的视图模型 public class CreateAppointment { public string SuperOfficeEmail { get; set; } } 在控制器中,我有这样的方法 public ActionResult Create() { return View(); } public ActionResult Per

我正在尝试在我的Asp.NETMVC应用程序中创建一个自动完成框。 这就是我到现在为止所做的 我的视图模型

public class CreateAppointment
{
    public string SuperOfficeEmail { get; set; }
}
在控制器中,我有这样的方法

    public ActionResult Create()
    {

        return View();
    }

    public ActionResult Person(string searchText)
    {
        var persons = FindPersons(searchText);
        return Content(?? don't know what to do)
    }
在我看来

@model DatePicker.Models.ViewModels.CreateAppointment
@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Create</h2>
@using(Html.BeginForm("Create","Appointment"))
{
   @Html.TextBoxFor(m=>m.SuperOfficeEmail)
}

<script src="~/Scripts/jquery-ui-1.10.4.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("#SuperOfficeEmail").
        autocomplete('@Url.Action("Persons", "Appointment")', { minChars: 1 });   
        });

</script>
我想做的是,当自动完成出现时,将FirstName+LastName显示为文本,当用户选择某些选项时,我将电子邮件作为文本框的值。就像我们在下拉列表中做的那样。 这是否可能(可能使用Ajax?)?我该怎么做?
我以前没有使用过autocomplete,一直在关注这个网站,而且我对jquery也很陌生。

您所描述的并不是真正的autocomplete,它更像是一个按名称搜索功能,将电子邮件地址放入文本框中。。。这对用户来说是违反直觉的。也许最好在文本框旁边有一个[…]按钮,用户可以单击该按钮在模式对话框中执行搜索。只要我的2美分……是的,我想要更像一个dropdownlist,比如说,你可以在哪里搜索dropdownlist,每次用户键入内容时,dropdownlist都会被匹配的文本过滤掉(比如说,基于名字)。奇怪的情况然后看看jQuery的许多类似组合框的插件。这才是你真正需要的。
public class AddressBookPerson
{
    public string Email { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}