我正在尝试在用户单击链接时打开一个模式窗口(我认为它是弹出窗口的名称)。此窗口将包含其他信息。
这是一个链接示例:
@Html.ActionLink(Model[i].mMasterCard.mCardName, "DisplayCardDetails", "Card", new { @_cardId = Model[i].mMasterCard.mCardID }, new {@class = "@selected dialog"} )
您看到添加了一个 css 类,这是因为我尝试过这个:
$(function() {
$('a.dialog').click(function() {
var url = $(this).attr('href');
var dialog = $('<div style="display:none"></div>').appendTo('body');
dialog.load(url, {}, function (responseText, textStatus, XMLHttpRequest) {
alert("let's check it");
dialog.dialog({
close: function (event, ui) {
alert("This is hit!");
dialog.remove();
}
});
});
return false;
});
});
在这些行中,第一个警报"let's check it"
出现了,但从来没有第二个警报。
在我的一个控制器中调用以下操作:
public ActionResult DisplayCardDetails(int? _cardId)
{
if (_cardId == null)
{
TempData[MessageDomain.Tags.TEMPDATA_MESSAGE_ERROR] = NODATAFOUND;
return RedirectToAction("DisplayCardsResults");
}
if (_cardId == 0)
{
TempData[MessageDomain.Tags.TEMPDATA_MESSAGE_ERROR] = NODATAFOUND;
return RedirectToAction("DisplayCardsResults");
}
CardDisplay cardToDisplay = mCardManager.GetCardDisplayByID((int)_cardId);
if (cardToDisplay == null)
{
TempData[MessageDomain.Tags.TEMPDATA_MESSAGE_ERROR] = NODATAFOUND;
return RedirectToAction("DisplayCardsResults");
}
mCardItem = new CardItemPriceList
{
mCard = cardToDisplay,
mItemPriceLists = mPriceListManager.ListLatestPriceListsByCardId(cardToDisplay.mMasterCard.mCardID)
};
mPriceListManager.BuildCardItemsBestPrices(mCardItem);
return PartialView(mCardItem);
}
最后,部分观点:
@using MvcMagicAdmin.Models @using MvcMagicAdmin.Utilities.General @model MvcMagicAdmin.Utilities.CardItemPriceList
@if (Model.mCard != null)
{
{
ViewBag.Title = Model.mCard.mMasterCard.mCardName + " - (" + Model.mCard.mMasterCard.mCardSet.mCardSetName + ")";
}
if (Model.mCard.mMasterCard.mCardFlagFace == CardInfo.FlagFaceValue.Normal)
{
<h2>@Model.mCard.mMasterCard.mCardName Details</h2>
}
else
{
<h2>@Model.mCard.mMasterCard.mCardName \\ @Model.mCard.mChildCard.mCardName Details</h2>
}
<p>
@Html.ActionLink("Edit", "EditCard", new { _cardId = Model.mCard.mMasterCard.mCardID }) |
@Html.ActionLink("Back to List", "DisplayCardsResults")
</p>
using (Html.BeginForm())
{
<div id="multiCardDisplay" class="formStyle">
@{
Html.RenderAction("CardDetailsPartial", "PartialViews", Model.mCard);
}
<div class="float-left baseFontSize">
<p>
Highest Price:
</p>
<p>
Provider:
</p>
<p>
Middle Price:
</p>
<p>
Provider:
</p>
<p>
Lowest Price:
</p>
<p>
Provider:
</p>
</div>
<div class="align-right baseFontSize bold">
@if (Model.mCardHighestPrice != null)
{
<p>Highest Price = @Model.mCardHighestPrice </p>
}
else
{
<p>@Html.Label(ValueDomain.FIELD_UNAVAILABLE)</p>
}
@if (!String.IsNullOrEmpty(Model.mCardHighestPriceProvider))
{
<p>Provider: @Model.mCardHighestPriceProvider</p>
}
else
{
<p>@Html.Label(ValueDomain.FIELD_UNAVAILABLE)</p>
}
@if (Model.mCardMiddlePrice != null)
{
<p>Middle Price = @Model.mCardMiddlePrice </p>
}
else
{
<p>@Html.Label(ValueDomain.FIELD_UNAVAILABLE)</p>
}
@if (!String.IsNullOrEmpty(Model.mCardMiddlePriceProvider))
{
<p>
Provider: @Model.mCardMiddlePriceProvider
</p>
}
else
{
@Html.Label(ValueDomain.FIELD_UNAVAILABLE)
}
@if (Model.mCardLowestPrice != null)
{
<p>
Lowest Price = @Model.mCardLowestPrice
</p>
}
else
{
<p>@Html.Label(ValueDomain.FIELD_UNAVAILABLE)</p>
}
@if (!String.IsNullOrEmpty(Model.mCardLowestPriceProvider))
{
<p>Provider: @Model.mCardLowestPriceProvider</p>
}
else
{
<p>@Html.Label(ValueDomain.FIELD_UNAVAILABLE)</p>
}
</div>
@if (Model.mItemPriceLists.Count > 0)
{
<label>
Lastest Price List for this card:
</label>
<table>
<tr>
<th>Provider</th>
<th>@Html.ActionLink("Price Low", "ShowCardDetails", new { _sortOrder = ViewBag.LowSortParm } )</th>
<th>@Html.ActionLink("Price Mid", "ShowCardDetails", new { _sortOrder = ViewBag.MidSortParm } )</th>
<th>@Html.ActionLink("Price High", "ShowCardDetails", new { _sortOrder = ViewBag.HighSortParm } )</th>
<th>Date</th>
</tr>
@for (int i = 0; i < Model.mItemPriceLists.Count; i++)
{
var className = i%2 == 0 ? "even" : "odd";
<tr class="@className">
<td>@Html.ActionLink(Model.mItemPriceLists[i].mPriceListProvider.mPriceProviderName, "PriceProviderDetails", "PriceProvider", new { @_providerId = Model.mItemPriceLists[i].mPriceListProvider.mPriceProviderID}, null)</td>
<td>
@if (Model.mItemPriceLists[i].mPriceLow != 0.00m)
{
@(Model.mItemPriceLists[i].mPriceLow != null ? Html.DisplayFor(_item => _item.mItemPriceLists[i].mPriceLow) : Html.Label(ValueDomain.NOPRICELISTYET))
}
else
{
<span>@ValueDomain.NOPRICELISTYET</span>
}
</td>
<td>
@if (Model.mItemPriceLists[i].mPriceMid != 0.00m)
{
@(Model.mItemPriceLists[i].mPriceMid != null ? Html.DisplayFor(_item => _item.mItemPriceLists[i].mPriceMid) : Html.Label(ValueDomain.NOPRICELISTYET))
}
else
{
<span>@ValueDomain.NOPRICELISTYET</span>
}
</td>
<td>
@if (Model.mItemPriceLists[i].mPriceHigh != 0.00m)
{
@(Model.mItemPriceLists[i].mPriceHigh != null ? Html.DisplayFor(_item => _item.mItemPriceLists[i].mPriceHigh) : Html.Label(ValueDomain.NOPRICELISTYET))
}
else
{
<span>@ValueDomain.NOPRICELISTYET</span>
}
</td>
<td>@Html.DisplayFor(item => item.mItemPriceLists[i].mPriceListDate)</td>
</tr>
}
</table>
}
else
{
<span id="emptyMessage">There are no items that matches your search parameters. Please try again.</span><br/>
}
<div class="buttonField">
<input type="submit" name="_submitButton" value="Get Latest Prices" style="width: 150px"/>
</div>
</div>
}
}
else
{
<span id="emptyMessage">@MessageDomain.ERROR_PROCESSING</span><br/>
}
虽然我知道(通过调试)该DisplayCardDetails
方法被调用并成功完成了它的工作,但实际上并没有打开任何窗口。我需要先通知用户窗口正在加载(因为操作方法需要几秒钟才能加载),然后打开弹出窗口。我一直在尝试这样做一段时间,并且非常感谢一些很好的帮助。
编辑
作为旁注,我主要使用最新的 Chrome 进行调试。