webapi项目如何从客户端接受值并将其传递给.html?
How does webapi project accepts value from client and pass it to .html?
服务器端是一个.NetCore WebAPI项目(不是MVC),它存储了一个名为
的文件
greeting.html
...
<td class="class1">Hi</td>
...
以前客户端只想从服务器打开这个.html文件(假设localhost
是服务器):
Process.Start(new ProcessStartInfo("https://localhost:5001/greeting/greeting.html"));
现在客户端要将字符串 name
传递给此 .html 文件然后打开它:
...
<td class="class1">Hi {name}</td>
...
我怎样才能做到这一点?谢谢。
将所需的参数添加到您的文件 url,如下所示:
Process.Start(new ProcessStartInfo("https://localhost:5001/greeting/greeting.html?name=Simon&age=25"));
然后您可以像这样在 html 文件中获取它们:
<html>
<body>
Hello <Label id="name" />
<script>
urlParams = new URLSearchParams(window.location.search);
nameParam = urlParams.get('name');
document.getElementById('name').innerHTML = nameParam;
</script>
</body>
</html>
服务器端是一个.NetCore WebAPI项目(不是MVC),它存储了一个名为
的文件greeting.html
...
<td class="class1">Hi</td>
...
以前客户端只想从服务器打开这个.html文件(假设localhost
是服务器):
Process.Start(new ProcessStartInfo("https://localhost:5001/greeting/greeting.html"));
现在客户端要将字符串 name
传递给此 .html 文件然后打开它:
...
<td class="class1">Hi {name}</td>
...
我怎样才能做到这一点?谢谢。
将所需的参数添加到您的文件 url,如下所示:
Process.Start(new ProcessStartInfo("https://localhost:5001/greeting/greeting.html?name=Simon&age=25"));
然后您可以像这样在 html 文件中获取它们:
<html>
<body>
Hello <Label id="name" />
<script>
urlParams = new URLSearchParams(window.location.search);
nameParam = urlParams.get('name');
document.getElementById('name').innerHTML = nameParam;
</script>
</body>
</html>