首页 > 解决方案 > jquery自动完成选择事件,显示动作数据

问题描述

在选择事件自动完成时,我想在我的控制器中调用 JsonResult 操作来显示数据库中的数据。

函数JS

select: function (e, i) {
                $("#idp").val(i.item.val);
                $.ajax({
                    type: 'Post',
                    dataType: "json",
                    contentType: "application/json; charset=utf-8",
                    url: '/controller/action/',
                    data: "{ 'id': '" + i.item.val + "'}",
                    success: function (data) {
                        // code to put here//
                        $("#mydiv").html(data);
                    }

                })
            },

标签: jqueryasp.net-mvcasp.net-ajax

解决方案


我的行动

public ActionResult ListObject(int? idpatient)
    {
         return PartialView(MyList);
    }

我的观点

@model IEnumerable<MyProject.Models.Object> table class="table">
<tr>
    <th>
        @Html.DisplayNameFor(model => model.IdNumber)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Name)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.FirstName)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Date)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Phone)
    </th>
    <th>
       Actions
    </th>
</tr>

@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.IdNumber)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.FirstName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Date)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Phone)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
            @Html.ActionLink("Details", "Details", new { id = item.Id }) |
            @Html.ActionLink("Delete", "Delete", new { id = item.Id })
        </td>
    </tr>
}

我有一个自动完成归档,我想在 slect 事件上调用我的操作并用数据填充视图


推荐阅读