mvcアプリのjqmodal内でjqueryウィジェットをいじり始めました。
最初は、
- [追加]リンクをクリックしてアラート(「賞品」)を取得し、次に[キャンセル]をクリックしてモーダルを閉じて目的の結果を得ることができます。
- 次に、[編集]リンクをクリックして、同じ目的の結果を得ることができます。
- ただし、最初に[リンクの編集]をクリックしてから、[追加]リンクをクリックしようとすると、「忘れて」アラートが表示されません(つまり、ウィジェットが初期化されませんでした)。
- ただし、戻って[編集]をクリックして賞品(アラートメッセージ)を取得することはできます。
ajax: "/ Home / EditPrintAdLine"およびajax: "/ Home / AddPrintAdLine"は、ウィジェットを初期化する要素(フィールド名はPrintAdLine_RunDate)を含む同じWebユーザーコントロールを最終的にレンダリングします。
何か案は?
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
</asp:Content>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<div id="printAdLineEditDialog" class="jqmWindow"></div>
<div id="printAdDialog" class="jqmWindow"></div>
<table>
<tr><td><a id="printAdLineItem" href="#">Add a Line Item</a></td></tr>
<tr><td><a id="editPrintAdLine" href="#">Edit</a></td></tr>
</table>
<script type="text/javascript">
$(document).ready(function() {
$.widget("ui.my_widget", { _init: function() { alert("My widget was instantiated"); } });
// Add line
$('#printAdDialog').jqm({
ajax: "/Home/AddPrintAdLine",
trigger: '#printAdLineItem',
onLoad: function(hash) {
$('#PrintAdLine_RunDate').my_widget();
}
});
// Edit line
$('#printAdLineEditDialog').jqm({
ajax: "/Home/EditPrintAdLine",
trigger: '#editPrintAdLine',
onLoad: function(hash) {
$('#PrintAdLine_RunDate').my_widget();
}
});
});
</script>
</asp:Content>