Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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# 通过AJAX(ASP.NET MVC)从数据库中选择数据_C#_Jquery_Asp.net_Ajax_Asp.net Mvc - Fatal编程技术网

C# 通过AJAX(ASP.NET MVC)从数据库中选择数据

C# 通过AJAX(ASP.NET MVC)从数据库中选择数据,c#,jquery,asp.net,ajax,asp.net-mvc,C#,Jquery,Asp.net,Ajax,Asp.net Mvc,我有一个数据库,里面有公司表、职位空缺表、面试表和问询表 这是它的方案 所以空缺和公司有关,面试和空缺有关,问句和面试有关 我实现了公司的下拉列表,当我选择公司空缺下拉列表更新时 下面是查看的代码 <div style="width: 100%; margin-left: 20px;height: 15%;padding-top: 20px;"> @Html.DropDownList("Company", ViewBag.Companies as SelectList, "

我有一个数据库,里面有公司表、职位空缺表、面试表和问询表

这是它的方案

所以空缺和公司有关,面试和空缺有关,问句和面试有关

我实现了公司的下拉列表,当我选择公司空缺下拉列表更新时

下面是查看的代码

<div style="width: 100%; margin-left: 20px;height: 15%;padding-top: 20px;">
    @Html.DropDownList("Company", ViewBag.Companies as SelectList, "Компания", new { @class = "greeting", @style = "width:30%; margin-left:20px;" })
    <select class="greeting" id="vacancy" name="id"  style="width:30%; margin-left:150px;" data-url="@Url.Action("Vacancies","Questions")">
        <option value="" disabled selected>Вакансия</option>
    </select>
</div>

我需要如何编写对后端的ajax调用并在div中显示数据?

您好,我不确定有什么不符合您的要求,您对逻辑有一定的了解,这正是您需要的实现

$("#Company").change(function (e) {
    var companyId = $(this).val();
    var model = {
        companyId:companyId
    };

    $.ajax({
        url: '@Url.Action("Vacancies","Questions")',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify(model),
        type: 'POST',
        dataType: 'json',
        processData: false
    })
    .success(function (result) {
        console.log(result);
        console.log(result.Vacancies);

    })
    .error(function (xhr, status) {
    alert("error");
});

});
控制器

public ActionResult Vacancies(int companyId)
{
    // Logic to get the vacancies data
    var result = "abc";
    return Json(new { Vacancies = result }, JsonRequestBehavior.AllowGet);
}
我希望上面的实现对您有所帮助。
谢谢

您好,我不确定什么地方不符合您的要求,您对逻辑有理解,这正是您需要的实现

$("#Company").change(function (e) {
    var companyId = $(this).val();
    var model = {
        companyId:companyId
    };

    $.ajax({
        url: '@Url.Action("Vacancies","Questions")',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify(model),
        type: 'POST',
        dataType: 'json',
        processData: false
    })
    .success(function (result) {
        console.log(result);
        console.log(result.Vacancies);

    })
    .error(function (xhr, status) {
    alert("error");
});

});
控制器

public ActionResult Vacancies(int companyId)
{
    // Logic to get the vacancies data
    var result = "abc";
    return Json(new { Vacancies = result }, JsonRequestBehavior.AllowGet);
}
我希望上面的实现对您有所帮助。
感谢

下面是从Action方法获取json的ajax调用,它可以是下拉更改或其他一些您希望成功的事件创建您的表结构并将其附加到正文中(如果只是示例代码)

    $.ajax({
            url: '@Url.Action("QuestionBlocks","YourController")',
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify(model),
            type: 'Get',
            dataType: 'json',
            processData: false
        })
        .success(function (result) {
           // Here do some stuff with your JSON to bind that in Table 
         var trHTML = '';

         $.each(data.Countries, function (i, item) {

          trHTML += 'Your Table Structure';
         });

          $('#YourID').append(trHTML);
        })
        .error(function (xhr, status) {
        alert("error");
     });

下面是从Action方法获取json的ajax调用,它可以是在下拉列表中更改,也可以是在成功时需要的其他事件创建表结构并将其附加到正文中(如果只是示例代码的话)

    $.ajax({
            url: '@Url.Action("QuestionBlocks","YourController")',
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify(model),
            type: 'Get',
            dataType: 'json',
            processData: false
        })
        .success(function (result) {
           // Here do some stuff with your JSON to bind that in Table 
         var trHTML = '';

         $.each(data.Countries, function (i, item) {

          trHTML += 'Your Table Structure';
         });

          $('#YourID').append(trHTML);
        })
        .error(function (xhr, status) {
        alert("error");
     });

那么你的问题是什么呢?你已经找到了一个解决方案,似乎你已经意识到了这个解决方案。我的问题是,我需要如何正确地发出get请求,以及我需要如何在服务器端编写方法@好奇设备将与您在“空缺”下拉列表中所做的相同“现在填写”在您的案例中,关于空缺的更改,您需要填写问题,而不是替换$Company.changefunction e{您必须填写$空缺.changefunction e{将vacancyid传递给companyId,然后在这里用适当的逻辑编写方法,就像为vacancyI更新我的post@Curiousdevincrease显示问题的区域的高度,或者减少行的高度,减少行之间的填充物等等。那么你的问题是什么?你已经找到了一个答案n解决方案,您似乎知道解决方案我的问题是我需要如何正确发出get请求,以及我需要如何在服务器端编写方法?@CuriousDevice将与您在“空缺”下拉列表中所做的相同。在您的空缺更改案例中,您需要填写问题,而不是替换$Company。changefunction e{您必须写入$SPANCE.CHANGE函数{将vacancyid传递给companyId,然后在这里用适当的逻辑编写方法,就像为vacancyI更新我的post@Curiousdevincrease显示问题的区域的高度,或减少行的高度,减少行之间的填充物等…谢谢的伙计,我会试试。谢谢的伙计,我会的尝试