Asp.net mvc 在MVC中调用重定向时显示弹出视图
场景:Asp.net mvc 在MVC中调用重定向时显示弹出视图,asp.net-mvc,Asp.net Mvc,场景: 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.
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);
}
如果用户在输入之前临时保存的AWB编号后按tab键,则必须在运行时填充所有ex值
问题:
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);
}
一切正常,但填充了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);
}
});
});
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);
}
这非常简单,之所以显示弹出窗口,是因为编写代码是为了显示:
$("#dialog").dialog({ appendTo: "#AWBNO" }).html(result);
上面的代码拾取#dialog
元素使用jQuery dialog()
方法将其附加到元素#AWBNO
中,然后.html()
方法将该对话框的标记更改为变量结果
根据您的authenticationAWB
操作,您可以在弹出窗口中看到的内容是:
请提供上述IGM编号的航空账单副本
再次验证
提供的空运提单编号无效,请根据公式进行验证。
重定向到操作(“编辑”,awbPart)代码>
重定向操作(“编辑”,awbPart)代码>当它返回新页面时,它的标记被添加到元素`#dialog'中,因此结果是弹出的
官方文件:
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);
}
控件是否附加了一些javascript。如果您不确定,您通常可以通过可视事件插件看到这一点。@Kaido yes场景的起点基于跟踪(#AWBId)的Jquery。onchange()并调用控制器方法authenticationawb()上面写过,但我认为javascript没有直接干扰可能是因为我有actionresult或redirectaction的问题不确定。你能包括javascript和帖子的回调吗?我想是的involved@Kaido我更新了我的问题,看一看。是的,那个特殊的函数看起来不相关。所以重定向到Edit发生了,然后Edit的内容是预期的,除了带有“Cities,Airline,…”的面板的样式是意外的?