Home > database >  asp net simple raw currency converter
asp net simple raw currency converter

Time:09-30

I am trying to create a simple currency converter with asp.net

I am using a simple form and the value is raw.

EX: amount entered 5 / amount displayed 5 * 5.2 -> 26

but for any reason i can't figure it out why it doesn't display the value.

@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;
            
            
        }
        
    }
}

CodePudding user response:

To achieve desired result you need to make two small changes in your Model page.

First change the amount to a property, and attach BindProperty attribute to it.

[BindProperty]
public double amount{get;set;}

Please revert, if this is working or not.

  • Related