如何在Webmatrix中使用Razor在两个页面之间传递值?

发布于 2024-12-23 11:20:58 字数 102 浏览 3 评论 0原文

我是 Razor 和 Webmatrix 的新手。我尝试使用 POST 方法将值从一个页面传递到另一个页面,但我无法传递值。我已经用谷歌搜索过但没有得到任何解决方案。那么有人可以给我指导吗?

I am new to Razor and Webmatrix.I was trying to pass values using POST method from one page to another page but i am not able pass values. I have googled on it but didn't get any solutions. So can any one provide me the guidance?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

还如梦归 2024-12-30 11:20:58

你有什么困难?在一个页面上创建一个

<form action="/foo.cshtml" method="post">
    <input type="text" name="bar" value="" />
    <button type="submit">OK</button>
</form>

并在另一页上从请求中读取值:Request["bar"]

@{
    var bar = Request["bar"];
}

What are you having difficulties with? On one page you create a <form>:

<form action="/foo.cshtml" method="post">
    <input type="text" name="bar" value="" />
    <button type="submit">OK</button>
</form>

and on the other page you read values from the request: Request["bar"]:

@{
    var bar = Request["bar"];
}
≈。彩虹 2024-12-30 11:20:58

如果两个页面都在同一个项目中,则典型的方法是:

  1. 将表单发布到特定控制器。
  2. 使用控制器参数,将数据传递到另一个页面的视图模型,并渲染视图

A typical way to do it if both pages are in the same project:

  1. Post the form to a specific controller.
  2. Using the controller arguments, pass the data to the view model of the other page, and render the View
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文