Ok, this is just testing data. If I have this razor page:
newtest.cshtml
```
@page
@{
var name = string.Empty;
if (Request.HasFormContentType)
{
name = Request.Form["name"];
}
}
<div style="margin-top:30px;">
<form method="post">
<div>Name: <input name="name" /></div>
<div><input type="submit" /></div>
</form>
</div>
<div>
@if (!string.IsNullOrEmpty(name))
{
<p>Hello @name!</p>
}
</div>
<a href="qstest?lastname=white">test</a> // this test querystring works to another page
```
It post to itself, and there is no problem.
If however I try to post to another razor page by changing
```
<form method="post">
// to
<form method="post" action="posttest">
```
The correct url loads, but just a blank page.
The posttest.cshtml being the same basic code as above.
I just can't get one page to post to another. Any ideas?
I tried github markup, having trouble here formatting code. I am used of ```.
Member
7 Points
27 Posts
Posting from one razor page to another.
Nov 30, 2018 06:15 AM|jimap_1|LINK
Ok, this is just testing data. If I have this razor page:
newtest.cshtml
```
@page
@{
var name = string.Empty;
if (Request.HasFormContentType)
{
name = Request.Form["name"];
}
}
<div style="margin-top:30px;">
<form method="post">
<div>Name: <input name="name" /></div>
<div><input type="submit" /></div>
</form>
</div>
<div>
@if (!string.IsNullOrEmpty(name))
{
<p>Hello @name!</p>
}
</div>
<a href="qstest?lastname=white">test</a> // this test querystring works to another page
```
It post to itself, and there is no problem.
If however I try to post to another razor page by changing
```
<form method="post">
// to
<form method="post" action="posttest">
```
The correct url loads, but just a blank page.
The posttest.cshtml being the same basic code as above.
I just can't get one page to post to another. Any ideas?
I tried github markup, having trouble here formatting code. I am used of ```.
Member
610 Points
200 Posts
Re: Posting from one razor page to another.
Nov 30, 2018 06:57 AM|Sherry Chen|LINK
Hi jimap_1 ,
You could try to use asp-page="./pageName" for linking rather than action , you could also use the "asp-page-handler" to Indicate the handler name.
Best Regards,
Sherry
Member
40 Points
32 Posts
Re: Posting from one razor page to another.
Nov 30, 2018 08:27 AM|AddWeb Solution|LINK
hi jimap_1,
if you are working with asp.net mvc and Posting from one razor page to another than use below code.
and if you are working with asp.net core with mvc and posting from one razor page to another than use below code.
Member
7 Points
27 Posts
Re: Posting from one razor page to another.
Nov 30, 2018 10:24 PM|jimap_1|LINK
Thanks to all who answered, what worked is:
I was used to older razor web pages, this stuff is different in .net core razor pages, a learning curve.