【问题标题】:Can a partial view be used to do Ajax item updates?可以使用局部视图进行 Ajax 项目更新吗?
【发布时间】:2010-12-22 04:40:18
【问题描述】:

我有一张根据缺陷代码列表构建的表格。

每行的一部分可以加载带有提交按钮的子表项吗?

示例表:

<table><tr>
<th>Code</th><th>Description</th>
<th>Impact to your customers</th>
<th>Impact to your associates</th>
<th>Save</th>
<th>Save Errors</th></tr>

前 2 列是从查找表中填充的,接下来的 3 列是一个表单,因此用户可以设置值或从以前的值更新它们。

我能否以某种方式让每行有 3 个 TD 项目一个单独的 Ajax 表单,其中 codeId 作为隐藏值嵌入?我的强类型视图会继承什么?外层会继承IEnumerable&lt;DefectDTO&gt;,部分视图会继承AssessmentDTO类型?

这是我正在尝试使用的实际表格:

<table>
    <tr>

        <th>
            Code
        </th>
        <th>
            Description
        </th>
        <th>
            Document
        </th>
        <th>
            Customer Contact Required for Resolution
        </th>
        <th>
            AssociateSeverity
        </th>
        <th>
            ShareholderSeverity
        </th>
        <th>
            CustomerSeverity
        </th>
        <th>
            RegulatorySeverity
        </th>
        <th>
            RootCause
        </th>
        <th>
            Investor Requirements*
        </th>
    </tr>

<% foreach (var item in Model.DefectCodes) { %>

    <tr>
        <% using (Ajax.BeginForm("Create", new AjaxOptions() ))
           {%>
        <td>
            <%= Html.Encode(item.Code)%>
        </td>
        <td>
            <%= Html.Encode(item.Description)%>
        </td>
        <%  Html.RenderPartial("Create",null, ViewData); %><!-- This is where the form is -->
        <% } %>
    </tr>

<% } %>

</table>

【问题讨论】:

  • 您可以添加更多详细信息,例如您正在使用的模型吗?据我了解,您的表格中需要一个部分表格,有两个不同的模型,一个显示前两列,另一个用于表格,但是为什么每行都有两个按钮(保存和保存错误)?
  • 只有 1 个按钮,保存。最后一列是验证摘要/验证错误。如果这不能充分显示我想要完成的工作,我可以在明天的工作中添加更多细节。

标签: asp.net-mvc ajax partial-views asp.net-mvc-ajax asp.net-mvc-partialview


【解决方案1】:
<% foreach (var item in Model.DefectCodes) { %>

    <tr>
        <% using (Ajax.BeginForm("Create", new AjaxOptions() ))
           {%>

        <!--should be easy like this!--><!--ur codeid here-->
        <%=Html.HiddenFor(modelItem => item.codeid)%> 

        <td>
            <%= Html.Encode(item.Code)%>
        </td>
        <td>
            <%= Html.Encode(item.Description)%>
        </td>
        <%  Html.RenderPartial("Create",null, ViewData); %><!-- This is where the form is -->
        <% } %>
    </tr>

<% } %>

</table>

它只是解决了你隐藏的价值!问题..

你不需要把它放到TD 因为你希望它被隐藏所以它仍然会为你获得价值但不会在表格或表格或视图中显示..这样你可以保持3 TD 并获得比表格上显示的更多的价值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多