Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

asp net simple raw currency converter

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading