我构造了一个web方法,它创建一个html格式的字符串。
我想将字符串传递到视图中,但不起作用。
你能帮我找到解决这个问题的正确方法吗。
let table = @TMDIWebApiController.GetAssets()
let string = "<table><tr><td>AssetId</td><td>ClientId</td><td>DateOfStatement</td><td>InvestmentType</td><td>Category</td><td>Isin</td><td>IsinDescription</td><td>IsinCurrency</td><td>TradingVenue</td><td>ShareHolding</td><td>TotalIssuedShares</td><td>Notes</td><td>IsCurrent</td><td>DateTo</td><td>DateFrom</td><td>LastModified</td></tr><tr><td>2</td><td>test</td><td>15.12.2021 23:32:07</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>True</td><td>15.12.2021 23:32:07</td><td>15.12.2021 23:32:07</td><td>15.12.2021 23:32:07</td></tr></table>"
<h2> Data</h2>
<p id="demo"> </p>
<button type="button" onclick='document.getElementById("demo").innerText = table'>Click Me!</button>
<!DOCTYPE html>
<html>
<body>
<h2> Data</h2>
<p id="demo"> </p>
<button type="button" onclick='document.getElementById("demo").innerHTML = table'>Click Me!</button>
<script>
var table = ""
var string = "<table><tr><td>AssetId</td><td>ClientId</td><td>DateOfStatement</td><td>InvestmentType</td><td>Category</td><td>Isin</td><td>IsinDescription</td><td>IsinCurrency</td><td>TradingVenue</td><td>ShareHolding</td><td>TotalIssuedShares</td><td>Notes</td><td>IsCurrent</td><td>DateTo</td><td>DateFrom</td><td>LastModified</td></tr><tr><td>2</td><td>test</td><td>15.12.2021 23:32:07</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td><td>True</td><td>15.12.2021 23:32:07</td><td>15.12.2021 23:32:07</td><td>15.12.2021 23:32:07</td></tr></table>"
try{
table =TMDIWebApiController.GetAssets()
}
catch{
console.error('Unable to get HTML data from webapi');
console.error('Passing the string into view is working');
table = string;
}
</script>
</body>
</html>