У меня есть страница .cshtml:
Код: Выделить всё
@page
@using RazorPages
@model IndexModel
@using (Html.BeginForm()) {
How old are you?
How much money do you have in your pocket?
}
Код: Выделить всё
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System;
using System.Threading.Tasks;
namespace RazorPages
{
public class IndexModel : PageModel
{
protected string money { get; set; }
protected string age { get; set; }
public IActionResult OnPost()
{
if (!ModelState.IsValid)
{
return Page();
}
return RedirectToPage("Index");
}
}
}
Следующий код index.cshtml.cs не работает:
Код: Выделить всё
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System;
using System.Threading.Tasks;
namespace RazorPages
{
public class IndexModel : PageModel
{
[BindProperty]
public decimal Money { get; set; }
[BindProperty]
public int Age { get; set; }
public IActionResult OnPost()
{
/* if (!ModelState.IsValid)
{
return Page();
}*/
this.Money = Money;
this.Age = Age;
System.IO.File.WriteAllText(@"C:\Users\Administrator\Desktop\murach\exercises\WriteText.txt",
this.Money.ToString());
return RedirectToPage("Index", new { age = this.Age, money = this.Money});
}
}
}
Код: Выделить всё
@page
@using RazorPages
@model IndexModel
@using (Html.BeginForm()) {
How old are you?
How much money do you have in your pocket?
}
Money: @Model.Money
Age: @Model.Age
Подробнее здесь: https://stackoverflow.com/questions/458 ... azor-pages
Мобильная версия