【发布时间】:2020-11-28 21:27:36
【问题描述】:
我是 Razor 页面的初学者,我正在尝试做一些非常基本的数据绑定。但是,我不明白为什么 .netcore 不绑定我的属性。
我在看这个帖子,但没有帮助:
ASP.NET Core Razor pages - not binding on POST Request
这是我的属性:
[BindProperty(SupportsGet = true)]
public int width { get; set; }
[BindProperty(SupportsGet = true)]
public int height { get; set; }
我的 onPost 和 onGet
public IActionResult OnGet(string type)
{
minLength = BarcodeConstants.BarCodeMinLength;
width = 256;
height = 256;
other stuff...
public IActionResult OnPost(string type)
{
minLength = BarcodeConstants.BarCodeMinLength;
Debug.WriteLine("Image width = " + width);
Debug.WriteLine("Image height = " + width);
other stuff...
这是我的cshtml。不知道这两个是不是搞砸了。
<form method="post" asp-page="QRBarCode">
<input type="text" placeholder="Input value" name="inputVal" value="@Model.inputVal" />
<input type="submit" value="Generate QR Barcode" />
</form>
<qrcode content="@Model.inputVal"
type="@Model.titleType"
alt="QR Code"
width="@Model.width"
height="@Model.height" />
<form method="post" class="mt-3" enctype="multipart/form-data" asp-page-handler="OnPost">
<div class="form-group row">
<div class="col-sm-10" style="max-width: 12rem;">
<input asp-for="@Model.width" class="form-control" placeholder="Image @Model.width" />
</div>
</div>
<div class="form-group row">
<div class="col-sm-10" style="max-width: 12rem;">
<input asp-for="@Model.height" class="form-control" placeholder="Image @Model.height" />
</div>
</div>
</form>
但是当我在宽度/高度字段中输入一个不同于 0 的值时,它总是在 onPost 中显示为零,请参阅日志
'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.5\System.Security.Principal.Windows.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Image width = 0
Image height = 0
我做错了什么?看起来很基础。感谢您的帮助。
谢谢。
【问题讨论】:
标签: c# .net-core razor-pages