Shah Abdullah
Shah Abdullah

Reputation: 405

Showing pop up View when calling redirect in MVC

Scenario :

The scenario is if user press tab after entering AWB No. which he previously temporary saved, all ex values must populate on run time.

Problem :

Everything is working fine but view which is populated with ex values is opening as a pop up.

It's working fine just opening a pop kind of view I want to refresh the current view only

JavaScript for onchange

<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);
        }
    });
});

Code for sending instance to Edit Method:

 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);
        }

Upvotes: 0

Views: 1023

Answers (1)

Syed Farjad Zia Zaidi
Syed Farjad Zia Zaidi

Reputation: 3360

This is very simple, the pop up is being displayed because your code is written to display that:

$("#dialog").dialog({ appendTo: "#AWBNO" }).html(result);

The code above picks up #dialog element uses jQuery dialog() method appends it to element #AWBNO and then .html() method changes the mark up of that dialog to the variable result.

According to your AuthenticatingAWB Action the content that you can expect in your pop up is:

  1. Duplicate Airway Bill Provided against above IGM No. , please verify again
  2. Invalid Airway Bill Number Provided, Please verify it according to formula.
  3. RedirectToAction("Edit", awbPart);

The content you have posted screenshots for is because of the RedirectToAction("Edit", awbPart); when it returns the new page it's mark up is added to element `#dialog' hence the result is in pop up.

The official documentation:

Upvotes: 1

Related Questions