Я следил за некоторыми статьями по объединению ASP.Net Webforms + MVC («Гибридный» сайт ASP.Net) для миграции одного из наших устаревших веб-приложений.Я думаю, что мне удалось получить большую часть функциональности в перенесенном приложении, но я обнаружил, что элементы управления, такие как gridviews, теряют свое состояние, когда я отправляю сообщение обратно (с использованием ASP.Net ajax на этом этапе).
Код выглядит примерно следующим образом, когда пользователь нажимает кнопку «Изменить» в строке:
public int GetActivityTypeId(int index)
{
// Get the row data from the grid
GridViewRow row = GrdContent.Rows[index]; << Rows is 0 in Hybrid app, works pre-conversion
// Cell 0 is the Id
return int.Parse(row.Cells[0].Text);
}
Элемент управления настроен следующим образом:
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GrdContent" runat="server" AutoGenerateColumns="false"
AllowPaging="false" CssClass="GridViewStyle" OnRowDeleting="GrdContentRowDeleting"
OnRowEditing="GrdContentRowEditing" OnRowDataBound="GrdContentRowDataBound">
<FooterStyle CssClass="GridViewFooterStyle" />
<RowStyle CssClass="GridViewRowStyle" />
<SelectedRowStyle CssClass="GridViewSelectedRowStyle" />
<AlternatingRowStyle CssClass="GridViewAlternatingRowStyle" />
<HeaderStyle CssClass="GridViewHeaderStyle" />
<Columns>
<asp:BoundField DataField="ID" />
<asp:BoundField DataField="Name" HeaderText="Activity Type Name" />
<asp:BoundField DataField="ParentActivityTypeName" HeaderText="Activity Type Parent" />
<asp:CommandField ShowEditButton="true" ShowDeleteButton="true" ButtonType="Link" />
</Columns>
</asp:GridView>
<ctl:CustomPager ID="PgrCustom" runat="server" OnPageIndexChanging="PgrCustomPageIndexChanging" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="BtnModalOkay" EventName="click" />
<asp:AsyncPostBackTrigger ControlID="BtnFilter" EventName="click" />
</Triggers>
</asp:UpdatePanel>
Устаревший код следуетШаблон MVP.
Я использую следующие статьи для преобразования: