【发布时间】:2021-04-10 20:07:55
【问题描述】:
我是 Razor 的新手,我正在尝试将数据从“Index.html”传递到“Quiz.html”,但我正在努力使用不同的教程将这些部分组合在一起。这是我到目前为止的地方。我正在尝试在不使用服务的情况下执行此操作,但我不确定是否可行。
谢谢!
索引.html
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-center">
<h1 class="display-4">Welcome, @Model.Name</h1>
<p>This is My Quiz App</a>.</p>
<form method="post">
<label>What's your name?</label>
<input type="text" asp-for="@Model.Visitor.Name">
<button type="submit">Send</button>
</form>
</div>
索引.cs
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
[ViewData]
[BindProperty]
public string Name { get; set; }
public Visitor Visitor { get; set; }
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}
public void OnGet()
{
Name = "Stranger";
}
public IActionResult OnPost()
{
return RedirectToPage("/Quiz", new { Visitor.Name });
}
}
}
测验.html
@page
@model QuizModel
@{
ViewData["Title"] = "Quiz Page";
}
<div class="text-center">
<h1 class="display-4">Thanks for checking my first website out, @Model.Name. Are you ready?</h1>
<p>Let's see how much you know about me.</a>.</p>
</div>
测验.cs
public class QuizModel : PageModel
{
[ViewData]
[BindProperty]
public string Name { get; set; }
public Visitor Visitor { get; set; }
public void OnGet()
{
Name = ?
}
【问题讨论】:
-
嗨@Pablo Aguirre de Souza,如果我的解决方案可行,你能接受它作为答案吗,谢谢!
标签: asp.net-core razor razor-pages