0

I want to return a View in a modal window. I've allready done it on different sites with an ajax call, but somehow this time the View is not returned. This is the ajax-call:

function fill() {
var ISIN = document.getElementById('ISIN').value
if (ISIN != null) {
    
        $.ajax({
            type: "POST",
            url: "/Order/FillFormWithISIN",
            data: {ISIN: ISIN},
            success: function (data) {
                $('.modal-body').html(data);
                $("#myModal").modal("show");
            },
            error: function () {
                $('.modal-body').html(data);
                $("#myModal").modal("show");
            }
        });
    }
    }

The Controller-function is called correctly, so the url must be correct.

This is the Controller-function:

public IActionResult FillFormWithISIN (string ISIN)
        {
            Instrument instrument = new Instrument { ISIN = ISIN};
            instrument.GetDetails();
            return PartialView("~/Views/Shared/multipleResultsPartial.cshtml", instrument); 
        }

When I debug the debugger just steps over the 'return PartialView' without doing anything.

Here is my PartialView:

    @model Instrument


@if (Model.Response.GetInstrumentInfosResponse1.Length > 0)
{
    @foreach (var inst in Model.Response.GetInstrumentInfosResponse1)
    {
        <div class="col-md-8">
            <p>@inst.Name</p> 
        <p>@inst.Ccy</p>
        </div>
    }
}
else { 
<p>An instrument with the given ISIN could not be found. Do you want to create an instrument?</p>
}

The url to the PartialView is also correct I allready checked that.

Here is my modal window in which I want the results to be returned:

<div class="modal fade" id="myModal" role="dialog">
        <div class="modal-dialog modal-lg">

            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" onclick="javascript:window.location.reload()" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Save Status</h4>
                </div>
                <div class="modal-body">
                    <div class="cv-spinner">
                        <span class="spinner"></span>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" onclick="javascript:window.location.reload()" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

I call the function like this:

<div class="col-md-2">
                <form>
                    <div class="form-group">
                        <label asp-for="ISIN" class="control-label">ISIN</label>
                        <input asp-for="ISIN" id="ISIN" class="form-control" value="@Model.ISIN" />
                        <span asp-validation-for="ISIN" class="text-danger"></span>
                        <button class="btn" onclick="fill()" id="searchButton"  disabled style="float:right; pointer-events: none;cursor: default">Search</button>
                    </div>
                </form>
            </div>

The output of the console window is this:

    Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executing action method NXM_Web_Client.Controllers.OrderController.FillFormWithISIN (NXM_Web_Client) - Validation state: Valid
"dotnet.exe" (CoreCLR: clrhost): "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Remote Debugger\x64\Runtime\Microsoft.VisualStudio.Debugger.Runtime.NetCoreApp.dll" geladen. 
Ausnahme ausgelöst: "System.IO.FileNotFoundException" in System.Private.CoreLib.dll
"dotnet.exe" (CoreCLR: clrhost): "Microsoft.GeneratedCode" geladen. 
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed action method NXM_Web_Client.Controllers.OrderController.FillFormWithISIN (NXM_Web_Client), returned result Microsoft.AspNetCore.Mvc.PartialViewResult in 7301.4469ms.
Microsoft.AspNetCore.Mvc.ViewFeatures.PartialViewResultExecutor:Information: Executing PartialViewResult, running view ~/Views/Shared/multipleResultsPartial.cshtml

So the PartialView is actually called, but not displayed in the modal.

I tried the comment out the 'instrument.GetDetails()'-Part to check if the View is returned then, but it is still not returned. So the issue isn't there. Sometimes when I debug I get in jQuery.js in a part of code with this comment: /

/ Discard the second event of a jQuery.event.trigger() and
                // when an event is called after a page has unloaded

Maybe this has something to do with the problem.

This is the Instrument Model:

    namespace NXM_Web_Client.Models
{
    public class Instrument
    {
        public GetInstrumentInfosResponse Response { get; set; }
        public ExtractInstrumentResponse Response2 { get; set; }
        public string InstName { get; set; }
        public long InstID { get; set; }
        public string InstAcr { get; set; }
        public long SecurityCode { get; set; }
        public string SecurityName { get; set; }
        public string ISIN { get; set; }

        /// <summary>
        /// Function that retrieves Information about the Instruments' Details from the Instrument-Webservice
        /// </summary>
        public void GetDetails()
        {
            InstrumentService_v1_0Client client = new InstrumentService_v1_0Client();
            client.ClientCredentials.UserName.UserName = "B019438";
            client.ClientCredentials.UserName.Password = "PASSWORD";
            client.Endpoint.EndpointBehaviors.Add(new SigmaLoggerMessageInspector());
            SoapSecurityHeader securityHeader = new SoapSecurityHeader("B019438", "PASSWORD");
            _ = new InstrumentInfoSearchCriteria();
            InstrumentInfoSearchCriteria searchCriteria;
            if (InstID != 0)
            {
                searchCriteria = new InstrumentInfoSearchCriteria()
                {
                    ISIN = ISIN,
                    SecurityCode = SecurityName,
                    SecurityType = SecurityCode,
                    ID = InstID,
                    IDSpecified = true,
                    Name = InstName
                };
            }
            else
            {
                searchCriteria = new InstrumentInfoSearchCriteria()
                {
                    ISIN = ISIN,
                    SecurityCode = SecurityName,
                    SecurityType = SecurityCode,
                    Name = InstName
                };
            }


            GetInstrumentInfos getInstrumentInfos = new GetInstrumentInfos()
            {
                InstrmtInfoCrit = searchCriteria
            };

            try
            {
                using (new OperationContextScope(client.InnerChannel))
                {
                    OperationContext.Current.OutgoingMessageHeaders.Add(securityHeader);
                    Response = client.GetInstrumentInfosAsync(getInstrumentInfos).GetAwaiter().GetResult();

                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        /// <summary>
        /// Function that extracts more specific Instrument Information about the Instruments from the Instrument-WebService.
        /// For example when calling the Details-View in the Portfolio.
        /// </summary>
        public void Extract()
        {
            InstrumentService_v1_0Client client = new InstrumentService_v1_0Client();
            client.ClientCredentials.UserName.UserName = "B019438";
            client.ClientCredentials.UserName.Password = "PASSWORD";
            client.Endpoint.EndpointBehaviors.Add(new SigmaLoggerMessageInspector());
            SoapSecurityHeader securityHeader = new SoapSecurityHeader("B019438", "PASSWORD");

            InstrumentInfoSearchCriteria instrumentInfoSearch = new InstrumentInfoSearchCriteria()
            {
                ID = InstID,
                Name = InstName,
                Acronym = InstAcr,
                SearchMode = SearchMode.EQ

            };

            InstrumentInfoSearchCriteria[] instrumentInfoSearchCriterias = new InstrumentInfoSearchCriteria[]
                    {
                        instrumentInfoSearch
                    };

            Filter filter = new Filter()
            {
                Instrument = instrumentInfoSearchCriterias
            };

            ExtractInstrument extractInstrument = new ExtractInstrument()
            {
                Filter = filter
            };
            using (new OperationContextScope(client.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(securityHeader);
                Response2 = client.ExtractInstrumentAsync(extractInstrument).GetAwaiter().GetResult();

            }
        }

        /// <summary>
        /// Function that retrieves the FIGI-Code from the FIGI-Webservice. (not done yet)
        /// </summary>
        public void GetFIGI()
        {
            string ID = "B025228-" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss"); //user in Config-file
            string version = "0.1"; //version in Config-File
            OpenFIGIServiceClient client = new OpenFIGIServiceClient();
            client.ClientCredentials.UserName.UserName = "B025228";
            client.ClientCredentials.UserName.Password = "hjH#1UL4";
            client.Endpoint.EndpointBehaviors.Add(new SigmaLoggerMessageInspector());
            getOpenFIGI openfigi = new getOpenFIGI
            {
                ISIN = this.Response.GetInstrumentInfosResponse1[0].ISIN
            };
            ESBHeader header = new ESBHeader
            {
                trackingID = ID,
                version = version
            };
            try
            {
                getOpenFIGIRequest request = new getOpenFIGIRequest { ESBHeader = header, getOpenFIGI = openfigi };
                using (new OperationContextScope(client.InnerChannel))
                {
                    getOpenFIGIResponse1 figi = client.getOpenFIGIAsync(header, openfigi).Result;
                }

            }
            catch (Exception)
            {
                //throw (e);
            }

        }

    }
}

I know that modals on this website must be working because I also call a modal on another button click on this site and this works without flaws. I'm out of ideas why it isn't working this time. Thanks for the help.

T.Naz
  • 125
  • 8
  • Do you have severl modals in the same page? – mj1313 Apr 21 '21 at 06:44
  • No I just have one modal. I call the same modal with different information displayed (results from different Controller) on a different button click allready. – T.Naz Apr 21 '21 at 06:47
  • What does this line do `instrument.GetDetails();` you said it `just steps over the 'return PartialView' `, maybe there are some error in this function. – mj1313 Apr 21 '21 at 07:09
  • The instrument.GetDetails calls a webservice to get the details of an instrument based on its ISIN. It works, other fuctions are also using it, and I see in the debugger that the result of this function is correct. But I will still look into it now. – T.Naz Apr 21 '21 at 07:15
  • I just tried the function while commenting this part out, and it still didn't work, so the issue is not there most likely. – T.Naz Apr 21 '21 at 07:21
  • Ok, can you show us the Instrument model. – mj1313 Apr 21 '21 at 07:25
  • Ok I will add it to the Problem Description – T.Naz Apr 21 '21 at 07:33
  • use a test controller action to return this view, check if there is any error. – mj1313 Apr 21 '21 at 08:29

1 Answers1

0

You must specify what you expect. In this case html.

    $.ajax({
        type: "POST",
        url: "/Order/FillFormWithISIN",
        dataType: 'html',
        data: {ISIN: ISIN},
        success: function (data) {
            $('.modal-body').html(data);
            $("#myModal").modal("show");
        },
        error: function () {
            $('.modal-body').html(data);
            $("#myModal").modal("show");
        }
    });

After you added more details it looks like you have a problem with your partial view. Controller is returning error. You could do something like this, to determinate details

    public IActionResult FillFormWithISIN(string ISIN)
    {
        try
        {
            Instrument instrument = new Instrument { ISIN = ISIN };
            instrument.GetDetails();
            return PartialView("~/Views/Shared/multipleResultsPartial.cshtml", instrument);
        }
        catch Exception(ex)
        {
            //your method to log exception
        }

    }
Adlorem
  • 1,457
  • 1
  • 11
  • 10
  • Does the controller actually returns view ? – Adlorem Apr 21 '21 at 07:12
  • Other functions in this Controller class are working fine except for this one, so I guess it returns Views normally. But this function doesn't return a View. – T.Naz Apr 21 '21 at 07:16
  • check success: function console.log(data) do you see data in console? – Adlorem Apr 21 '21 at 07:18
  • I checked the ouput and added it in the problem description, I don't see the data Iogged only that the Partial View is actually called. – T.Naz Apr 21 '21 at 07:30
  • Your controller actually returned error. That means that you have problem with your partial view. – Adlorem Apr 21 '21 at 13:31