我正在尝试用asp.net 创建一个简单的货币转换器
我使用的是一个简单的表单,其值是原始的。
EX:输入的金额5/显示的数量5*5.2->26
但不管出于什么原因,我都不明白为什么它没有显示值。
@page
@model Logbooks.Pages.ConverterModel
@{
}
<p>Enter the amount "£"</p>
<div asp-validation-summary="All"> </div>
<form method="Post">
<div> Amount: <input asp-for="amount" /> </div>
<input type="submit" />
</form>
<div id="result">@this.Model.amount</div>
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System;
using Microsoft.Extensions.Primitives;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace Logbooks.Pages
{
public class ConverterModel : PageModel
{
public double amount;
public void OnGet()
{
}
public void OnPost()
{
amount = amount * 5.2;
}
}
}
要获得所需的结果,您需要在Model页面中进行两个小的更改。
首先将金额更改为属性,并将BindProperty属性附加到该属性。
[BindProperty]
public double amount{get;set;}
请恢复,如果这是有效的或不起作用。