简体   繁体   English

使用ajax发布后,不会更新.cshtml上表中的值

[英]Values in table on a .cshtml are not being updated after a post using ajax

I need to show information on a table in 2.cshtml that is on another 1.cshtml page called using @Html.Action("Action","Controller"), depending on the row selected on a table inside of 1.cshtml, the problem is that the information is not being refresh after the view returns. 我需要在另一个使用1.Html.Action(“ Action”,“ Controller”)调用的1.cshtml页面上的2.cshtml中的表上显示信息,具体取决于在1.cshtml中的表上选择的行,问题是视图返回后信息没有被刷新。

When you select a row in table (1.cshtml) javascript gives me the value of the cell that i need from that row, after that i do a ajax post to my controller and it access it succesfully then my controller returns the view and access my 2.cshtml with the table, then it runs in my for to display the information, but the problem is that my 2.cshtml never reloads so the rows of my table are never updated. 当您在表(1.cshtml)中选择一行时,javascript会为我提供该行所需的单元格的值,此后,我向控制器执行ajax发布,并成功访问它,然后控制器返回视图并访问我的2.cshtml与表格一起运行,然后在我的for中运行以显示信息,但是问题是我的2.cshtml从未重新加载,因此表格的行从未更新。

Code for posting to controller 用于发布到控制器的代码

function submitForm(row) {
        var idTool = el('idTool').value = row.cells[0].innerHTML;
        var url_ = '../Tools/ToolTable';
        jQuery.ajax({
            type: "POST",
            url: url_,
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify({ idToolPost:idTool })
        });
}

Controller 调节器

[HttpPost]
public ActionResult ToolTable(int idToolPost)
{
    var entitieTool = new Models.ToolControlEntities2();
    List<Models.Tool> t = entitieTool.Tools.ToList();
    List<Models.Equip> eqp = entitieTool.Equips.Include(x => x.Equip_Tool).ToList();
    List<Models.Equip_Tool> eqpt = entitieTool.Equip_Tool.Include(x => x.Equip).Where(x => x.id_Tool == idToolPost).ToList();

    ToolEquip ttteqpceteqptflt = new ToolEquip(eqpt, t, eqp);
    ViewBag.SuccessMessage = "The information was succesfuly displayed.";

    return View(ttteqpceteqptflt);
}

Table to show result 表格显示结果

    <table>
        <div>
            <thead>
                <tr>
                    <th> Tool</th>
                    <th> Equip</th>
                    <th> Active</th>
                </tr>
            </thead>
        </div>
        <tbody>
            @for (int x = 0; x < Model.eqtool_.Count; x++)
            {
                <tr>

                    <td style="display: none"><input id="idEquip" name="eq[@x].id_Equip" type="hidden" value="@Model.eqtool_[x].id_Equip" /></td>
                    <td style="display: none"><input id="idEquip" name="eq[@x].id_Tool" type="hidden" value="@Model.eqtool_[x].id_Tool" /></td>
                    <td>@Model.eqtool_[x].Tool.Tool_Name</td>
                    <td>@Model.eqtool_[x].Equip.Equip_Name</td>
                    <td>@Html.CheckBox("@Model.eqtool_[x].active")</td>
                </tr>
            }
        </tbody>
    </table>

After it runs my for the page dosen't show the new information, here is where i think i'm missing a refresh somewhere. 它运行后,我的页面没有显示新信息,这是我认为我在某处缺少刷新的地方。

所以我解决了我的问题,我只使用了以下内容:该表保存在我的“ texto”变量中,然后我用下一行替换tbody(我需要的信息)

document.getElementById('tooltabletbody').innerHTML = texto; 

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

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