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">×</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.