情景:
方案是如果用户在输入之前临时保存的AWB编号后按Tab键,则所有ex值必须在运行时填充。
问题:
一切工作正常,但是使用ex值填充的视图将作为弹出窗口打开。
用于onchange的JavaScript
<script type="text/javascript">
$("#AWBNO").change(function () {
var AWB = $("#AWBNO").val();
var IGMa = $("#IGMa").val();
$.ajax({
url: '@Url.Content("~/IMPORTAWBs/AuthenticatingAWB")?awb=' + AWB + '&igm=' + IGMa,
async: false,
success: function (result) {
if (result == "Authenticated AWB!") {
$("input:disabled").removeAttr('disabled');
$("select:disabled").removeAttr('disabled');
$("#AWBNO").removeAttr('disabled');
$("#process").removeAttr('disabled');
$("#PAGENO").focus();
}
else {
$("#dialog").dialog({ appendTo: "#AWBNO" }).html(result);
$("input:enabled").prop('disabled', true);
$("select:enabled").prop('disabled', true);
$("#AWBNO").removeAttr('disabled');
$("#process").removeAttr('disabled');
$("#AWBNO").focus();
}
},
error: function (xhr, stats, errorMessage) {
alert(errorMessage);
}
});
});
将实例发送到编辑方法的代码:
public ActionResult AuthenticatingAWB(string awb, string igm)
{
if (igm != null && awb != null)
{
string igmNO = igm;
var IgmNo = context.IMPORTAWBs.Where(f => f.IGMNO == igmNO && f.AWBNO == awb).FirstOrDefault();
var awbPart = context.IMPORTAWBs.Where(f => f.AWBNO == awb && f.IGMNO != igm && (f.SHIPMENTTYPE == "Part" || f.SHIPMENTTYPE == "Short")).FirstOrDefault();
if (awbPart == null)
{
if (awb != null)
{
if (IgmNo == null)
{
return CheckAuthenticatedAWB(awb);
}
return Content("Duplicate Airway Bill Provided against above IGM No. , please verify again.");
}
else
{
IsAuthencatedAWB = false;
return Content("Invalid Airway Bill Number Provided, Please verify it according to formula.");
}
}
else
{
return RedirectToAction("Edit", awbPart);
}
}
return Content(null);
}
Edit.cshtml
public ActionResult Edit(int? id,IMPORTAWB RunTimeImportAWBInstance)
{
var awbno = TempData["AWBNO"];
var igmno = TempData["IGMNO"];
if (awbno != null && igmno != null)
{
var importawb = context.IMPORTAWBs.Where(x => x.AWBNO == awbno && x.IGMNO == igmno).FirstOrDefault();
var deliveryInfo = context.DELIVERYINFOes.Where(f => f.AWBNO == importawb.AWBNO).FirstOrDefault();
if (deliveryInfo != null)
{
DeliveryInfo(importawb, deliveryInfo);
}
DetailSessionHandleClass = context.IMPORTAWBDETAILs.Where(f => f.AWBNO == importawb.AWBNO).ToList();
ViewBagList();
ViewBag.PossibleIGM = context.IMPORTMANIFIESTs.Where(f => f.IGMNO == importawb.IGMNO).FirstOrDefault();
CargoEntities._olderInstancea = importawb;
return View(importawb);
}
else {
var importawb = (RunTimeImportAWBInstance == null) ? context.IMPORTAWBs.Where(x => x.AWBId == id).FirstOrDefault() : RunTimeImportAWBInstance;
var deliveryInfo = context.DELIVERYINFOes.Where(f => f.AWBNO == importawb.AWBNO).FirstOrDefault();
if (deliveryInfo != null)
{
DeliveryInfo(importawb, deliveryInfo);
}
DetailSessionHandleClass = context.IMPORTAWBDETAILs.Where(f => f.AWBNO == importawb.AWBNO).ToList();
ViewBagList();
ViewBag.PossibleIGM = context.IMPORTMANIFIESTs.Where(f => f.IGMNO == importawb.IGMNO).FirstOrDefault();
CargoEntities._olderInstancea = importawb;
return View(importawb);
}
答案 0 :(得分:1)
这很简单,弹出窗口正在显示,因为您的代码被编写为显示:
$("#dialog").dialog({ appendTo: "#AWBNO" }).html(result);
上面的代码选择#dialog
元素使用jQuery dialog()
方法将其附加到元素#AWBNO
,然后.html()
方法将该对话框的标记更改为变量结果。
根据您的AuthenticatingAWB
操作,弹出窗口中可以看到的内容是:
Duplicate Airway Bill Provided against above IGM No. , please
verify again
Invalid Airway Bill Number Provided, Please verify it according to formula.
RedirectToAction("Edit", awbPart);
您发布屏幕截图的内容是因为RedirectToAction("Edit", awbPart);
返回新页面时,它的标记被添加到元素`#dialog&#39;因此结果是弹出。
官方文档: