[英]Post form data to url in Razor
I'm trying to append data from a form to the Url of my page using Razor (adding a query string). 我正在尝试使用Razor(添加查询字符串)将表单中的数据附加到页面的Url中。 I've done this in ASP.NET Web Controls okay, but I would prefer to do this in Razor if it is possible?
我已经在ASP.NET Web控件中做到了,但是如果可能的话,我希望在Razor中做到这一点?
Here's a very basic version of my Razor script but currently the '@test' variable is empty on post: 这是我的Razor脚本的一个非常基本的版本,但是当前'@test'变量在发布时为空:
@{
<form id="test" method="post">
<input type="text" />
<input type="submit" value="Submit" />
</form>
if(IsPost){
var test = Request.Form["test"];
Response.Redirect(@Model.Url + "?test=" + @test);
}
}
As a sidenote, is there a way of achieving this without a POST method at all? 附带说明一下,有没有一种方法完全不需要POST方法?
As I understand you want to add input value in your test variable. 据我了解,您想在测试变量中添加输入值。 You should define id for input[text] or you should change it to
您应该为input [text]定义ID或将其更改为
Page: 页:
@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.GET, null))
{
<input type='text' name'test' id='test' />
<input type="submit" value="Submit" />
}
or your code 或您的代码
@{
<form method="get" action="@Model.Url">
<input type="text" name="test" id="test" />
<input type="submit" value="Submit" />
</form>
}
PS I'm not clearly understand your code, because you set POST method and want to process GET method. PS我不清楚您的代码,因为您设置了POST方法并想处理GET方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.