ASP.NET Core Razor Page如何在后台获得表单Post后的name-value值?
<p>后台用HttpContext.Request.Query["name1"]获得的是空串。</p>
<hr>
<p>前端脚本是这样的:</p>
<p>function formPost(url,params){<br>
var form = document.createElement("form");</p>
<pre><code>form.action = url;
form.method = "post";
form.target = "_self";
form.style.display = "none";
var item = {
name: '',
value: ''
}
params = params !==undefined ? params : item;
//添加参数
for(var i in params){
var opt = document.createElement("input");
opt.name = params[i].name;
opt.value = params[i].value;
form.appendChild(opt);
</code></pre>
<p>}</p>
<p>document.body.appendChild(form);</p>
<p>form.submit();</p>
<p>return form;<br>
}</p>
<p>function start(){<br>
var a = [{<br>
name: "data11",<br>
value: "value1"<br>
}];<br>
formPost('<a href="https://localhost:44329/Index/In" target="_blank">https://localhost:44329/Index/In</a>',a);<br>
}</p>
回答
HttpContext.Request.Form 是表单参数
HttpContext.Request.Query 是url 参数