简体   繁体   English

返回视图未返回 - ASP.NET MVC

[英]Return View not returning - ASP.NET MVC

Well, this sound simple, and I've done it a dozen times already in my project, but this time isn't working and I don't know why.嗯,这听起来很简单,我已经在我的项目中做了十几次了,但是这次不起作用,我不知道为什么。 I just want to call a view, that have the name of the controller method.我只想调用一个具有控制器方法名称的视图。 So, I have an Ajax POST in one of my Views, that is the following:所以,我的一个视图中有一个 Ajax POST,如下所示:

$(".btn-default").on("click", function (event, params) {
console.log($(".chosen-select").val());

$.ajax({
    url: '@Url.Action("EditPfEsp", "Lottery")',
    type: 'GET',
    dataType: 'html',
    cache: false,
    traditional : true,
    data: { bdoIds: $(".chosen-select").val() },
    success: function (response) {
    if (response.length > 0) {
    alert(response);
    }
    else {
    alert("response length zero");
    }
    }
    });

It calls the method EditPfEsp just fine, which is this:它调用 EditPfEsp 方法就好了,就是这样:

public ActionResult EditPfEsp(string[] bdoIds)
    {
        IEnumerable<PF> pF = new List<PF>();
        pF = service.GetPF();
        List<PF> pFList = new List<PF>();
        pFList = pF.ToList();
        List<PF> pfListFinal = new List<PF>();

        for (int i = 0; i < bdoIds.Count(); i++ )
        {
            for (int x = 0; x < pFList.Count(); x++)
            {
                int id = Convert.ToInt32(bdoIds[i]);
                int pfunc = Convert.ToInt32(pFList[x].Func);
                if (id == pfunc && (pFList[x].Tipo_sorteio == "ESPECIAL" || pFList[x].Tipo_sorteio == "especial" || pFList[x].Tipo_sorteio == "Especial"))
                {
                    pfListFinal.Add(pFList[x]);
                }
            }
        }

        IEnumerable<PF> pfIE = new List<PF>();
        pfIE = pfListFinal.AsEnumerable();

        return View(pfIE);
    }

But then, the method doesn't return the view EditPfEsp that I have (same directory and same controller as the others. What I am doing wrong? I can't get this working and I don't have idea why.但是,该方法不会返回我拥有的视图 EditPfEsp(与其他视图相同的目录和相同的控制器。我做错了什么?我无法让它工作,我不知道为什么。

edit编辑

This is the EditPfEsp view that I want to show from my controller这是我想从控制器显示的 EditPfEsp 视图

    @model IEnumerable<AldpModel.Entities.PF>



<h2>Editar ponderações de funcionários selecionados</h2>

<div class="filterbox">
    <table class="table">
        <tr>

            <th>
                <b>@Html.DisplayNameFor(model => model.Tipo_sorteio)</b>
            </th>
            <th>
                <b>@Html.DisplayNameFor(model => model.Funcionario)</b>
            </th>
            <th>
                <b>@Html.DisplayNameFor(model => model.Nome_Funcionario)</b>
            </th>
            <th>
                <b>@Html.DisplayNameFor(model => model.Ponderacao)</b>
            </th>
            <th>
                <b>@Html.DisplayNameFor(model => model.Incluir_sorteio)</b>
            </th>

            <th></th>
        </tr>

        @foreach (var item in Model)
        {
            <tr>

                <td>
                    @Html.DisplayFor(modelItem => item.Tipo_sorteio)
                </td>
                <td>
                        @Html.DisplayFor(modelItem => item.Funcionario)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Nome_Funcionario)
                </td>
                <td>
                        @Html.DisplayFor(modelItem => item.Ponderacao)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Incluir_sorteio)
                </td>

                <td>
                    @Html.ActionLink("Editar", "Edit", new { id = item.Funcionario }) |
                    @Html.ActionLink("Detalhes", "Details", new { id = item.Id }) |
                    @Html.ActionLink("Apagar", "Delete", new { id = item.Id })
                </td>
            </tr>
        }

    </table>
</div>

首先创建<div id='id'></div> ,然后点击您的特定操作结果进行编辑,以便操作结果返回给您 partialview(model) 然后将您的 partailveiw 附加到$("id").empty().append(response)

Modify your ajax function to include the error callback function as below:修改您的 ajax 函数以包含错误回调函数,如下所示:

$.ajax({
    url: '@Url.Action("EditPfEsp", "Lottery")',
    type: 'GET',
    dataType: 'html',
    cache: false,
    traditional : true,
    data: { bdoIds: $(".chosen-select").val() },
    success: function (response) {
      if (response.length > 0) {
      alert(response);
      }
      else {
      alert("response length zero");
      }
    }
    error: function(jqXHR, textStatus, errorThrown)
    {
       alert(textStatus);
       alert(errorThrown);
    }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM