0

我开发了一个 asp.net mvc3 应用程序。将有一个初始视图,用于搜索客户列表并加载另一个视图。我通过ajax $.get 函数来做到这一点。它在我的本地机器上运行良好。但是,这在服务器实例中不起作用。也没有错误消息。

代码:

SearchCust.cshtml:

@model fbpm.Models.UserDetail

@{
    ViewBag.Title = "Customer List";
}

<h2>Search for a Customer</h2>

 Customer ID : <input type="text" id="cust" name="cust"/>
<button class="btn btn-primary btn-large" type="button" onclick="handlesearch();"> Search </button>
<br />
<br />
<div id='custlist'> Enter the Customer ID in the above field and click Search </div>

<script type="text/javascript" language="javascript">
        $.get('@Url.Action("Index", "User")?id=' + document.getElementById("cust").value,
        function (viewResult) {
            $("#custlist").html(viewResult);
        }); 
    function handlesearch() {
        $.get('@Url.Action("Index", "User")?id=' + document.getElementById("cust").value,
        function (viewResult) {
            $("#custlist").html(viewResult);
        });

    }
</script>

代码:index.cshtml:

 @model IEnumerable<fbpm.Models.UserDetail>

@{
    Layout = null;
}

<h2>List of Customers</h2>
<button type="button" name="CreateUser" onclick="createuser();"> Create Customer </button>
<table>
    <tr>
        <th>
            User ID
        </th>
        <th>
            Password
        </th>
        <th>
            Customer Name
        </th>
        <th>
            Email ID
        </th>
        <th>
            Contact #1
        </th>
        <th>
            Contact #2
        </th>
        <th>
            Complete Address
        </th>
        <th>
            State
        </th>
        <th>
            Country
        </th>
        <th>
            Role
        </th>
        <th>
            PAN Number
        </th>
        <th>
            Project Name
        </th>
        <th>
            Booked Date
        </th>
        <th>
            Booked Amount
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    if (@Html.DisplayFor(modelItem => item.Role).ToString().Equals("400"))
    {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.UserID)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Password)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.UserName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.EmailID)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Contact1)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Contact2)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.FullAddress)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.State)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Country)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Role)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.PANNo)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ProjectName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.BookedDate)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.BookedAmount)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id = @Html.DisplayFor(modelItem => item.UserID) }) |
            @Html.ActionLink("Details", "Details", new { id = @Html.DisplayFor(modelItem => item.UserID) }) |
            @Html.ActionLink("Delete", "Delete", new { id = @Html.DisplayFor(modelItem => item.UserID) })
        </td>
    </tr>
    }
}

</table>

<script type="text/javascript" language="javascript">
    function createuser() {
        var url = '@Url.Action("Create")';
        window.location.href = url;
    }
</script>

现在,这个动作类是:

public ViewResult SearchCust() {
    return View();
}

public ViewResult Index(string id)
{
   var cust = db.UserDetails.Where(c => c.UserID.Contains(id)); 
   return View(cust.ToList());
}

我的浏览器给出了错误:它给出了一个错误“ReferenceError: jQuery is not defined”。不知道我应该在这里做什么。我在脚本文件中有 jquery 1.9.1 min 甚至 1.8。

请有人可以帮我解释为什么这个电话没有出现?

问候, 哈里

4

2 回答 2

0

*终于成功了!!:) 我所要做的就是调用 jquery src 文件并将用户帐户添加到数据库中!

谢谢你们。*

于 2013-06-02T08:48:29.247 回答
0

由于您的评论,请确保 jQuery 库是您加载的第一个脚本,就在您标记之后。通过您的浏览器确认它实际上也已加载。

<body>
    <!--your mark-up-->
    <!--jQuery script: either local file or from CDN (jQuery before jQuery UI)-->
    <!--rest of your scripts, putting the scripts that-->
    <!--are depended on in other scripts first-->
</body>
于 2013-06-02T06:10:59.010 回答