将参数值从一个视图转移到另一个视图?

时间:2022-09-19 11:49:11

i have 2 asp.net mvc views.

我有两个asp.net mvc视图。

view1.aspx and view2.aspx.

of course they are [HTTPGet] Actions for each view as well Models View1Model.cs and View2Model.cs

当然,它们是每个视图的[HTTPGet]操作,并对View1Model进行建模。cs和View2Model.cs

in view1.aspc I have a hyperlink <a href="\view2"></a>, by clicking on it I'am landing on view2.aspx. i want to pass some text message from view1 to view2 and display it on view2.aspx.

view1。我有一个超链接,点击它我将登陆view2.aspx。我想从view1传递一些文本消息到view2并在view2.aspx上显示它。

i want to do that with with POST method, how to do it?

我想用POST方法做这个,怎么做?

2 个解决方案

#1


1  

You can send a POST to any action by using an HTML form with the url as view2.aspx.

您可以通过使用HTML表单(url为view2.aspx)向任何操作发送文章。

Any fields within that form (eg a hidden field) are then sent as POST data and can be accessed via a parameter in the view2 action or can be bound to View2Model.

然后,该表单中的任何字段(如隐藏字段)都作为POST数据发送,可以通过view2动作中的一个参数访问,也可以绑定到View2Model。

You should use the Html.BeginForm() helper for this.

您应该为此使用Html.BeginForm()帮助程序。

#2


0  

I have to use just a proper HTML.ActionLink and thats it! Best answer is here

我必须使用一个合适的HTML。ActionLink事儿吧!最佳答案在这里

#1


1  

You can send a POST to any action by using an HTML form with the url as view2.aspx.

您可以通过使用HTML表单(url为view2.aspx)向任何操作发送文章。

Any fields within that form (eg a hidden field) are then sent as POST data and can be accessed via a parameter in the view2 action or can be bound to View2Model.

然后,该表单中的任何字段(如隐藏字段)都作为POST数据发送,可以通过view2动作中的一个参数访问,也可以绑定到View2Model。

You should use the Html.BeginForm() helper for this.

您应该为此使用Html.BeginForm()帮助程序。

#2


0  

I have to use just a proper HTML.ActionLink and thats it! Best answer is here

我必须使用一个合适的HTML。ActionLink事儿吧!最佳答案在这里