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

Sta*_*ark 0 webmatrix razor

我是Razor和Webmatrix的新手.我试图使用POST方法将值从一个页面传递到另一个页面,但我无法传递值.我已经google了,但没有得到任何解决方案.那么任何人都能为我提供指导吗?

Dar*_*rov 5

你有什么困难?在一个页面上,您创建一个<form>:

<form action="/foo.cshtml" method="post">
    <input type="text" name="bar" value="" />
    <button type="submit">OK</button>
</form>
Run Code Online (Sandbox Code Playgroud)

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

@{
    var bar = Request["bar"];
}
Run Code Online (Sandbox Code Playgroud)