从局部视图剥离表格单元格

时间:2014-03-17 15:58:42

标签: jquery html ajax asp.net-mvc razor

我有一个AJAX调用,用部分视图的内容替换表行。

这是与AJAX通话的链接...

@Ajax.ActionLink("Create Promise",
"CreatePromise",
new { id = Model.bookings.bookingid },
new AjaxOptions
{
    HttpMethod = "POST",
    InsertionMode = InsertionMode.Replace,
    UpdateTargetId = "insertedpromise",
    OnSuccess = "postmessage('Promise_Created_')"
},
    new { @class = "primaryButton" })

这是AJAX调用的目标...

<tr id="insertedpromise">
    <td></td>
</tr>
@if (Model.promises.Any())
{
    for (int i = 0; i < Model.promises.Count; i++)
    {
    <tr id="promise_@Model.promises[i].promiseid">
        @Html.Partial("_promises", Model.promises[i])
    </tr>
    }
 }

这是部分......

@model salesModel.promise

    @using (Ajax.BeginForm(
        "UpdatePromise",
        new AjaxOptions
        {
            HttpMethod = "POST",
            InsertionMode = InsertionMode.Replace,
            UpdateTargetId = "UpdatePromises" + Model.promiseid.ToString(),
            OnSuccess = "postmessage('promise_Updated_')"
        }))
{
    string thisdivid = "UpdatePromises" + Model.promiseid.ToString();

    <div id="@thisdivid">
        @Html.Hidden("promiseid", Model.promiseid)
        @Html.Hidden("bookingid", Model.bookingid)
        @Html.Hidden("updatedate", DateTime.Now)
        <td>
            @Ajax.ActionLink(" ",
            "DeletePromise", new { promiseid = Model.promiseid },
            new AjaxOptions
            {
                Confirm = "Delete?",
                HttpMethod = "POST",
                OnSuccess = "postmessage('promise_Deleted_" + Model.promiseid + "')"
            }, new { @class = "buttondelete" })
            <input type="submit" class="promisebtn btnupdate" value=" " />
        </td>
        <td>@Html.EditorFor(m => m.monetary)</td>
        <td></td>
        <td>@Html.TextAreaFor(c => c.note)</td>
        <td>@String.Format("{0:d}", Model.updatedate)</td>
        <td>@Html.DisplayFor(c => c.updatedby)</td>
     </div>

}

尝试让插入的部分进入现有表是很痛苦的,但现在的问题是......

* 当包含日期字段时 - @ Html.Hidden(&#34; updatedate&#34;,DateTime.Now)在这种情况下 - 所有表格单元格都从渲染的html * 中删除

似乎MVC注入以使用日历控件呈现输入字段的脚本是个问题。有什么想法吗?

此外,div标签和其他细微因素的许多组合会导致同样的问题。在不同的场景中,渲染引擎渲染没有表格单元格的部分

1 个答案:

答案 0 :(得分:0)

问题似乎是位于表格单元格之外的div。我重写了一些东西以摆脱那些div并将所有内容移到表格单元格中除了表单之外。我现在通过删除div来实现两种情况。