Я только что закончил работу над консольным приложением в ведьме. Я создал кредитный калькулятор. Мой код выглядит следующим образом:Кредитный калькулятор в ASP.NET от консольного приложения
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LoanCalculator
{
public class LoanCalculator
{
public static void Main(string[] args)
{
// declare variables
double principle = 0;
double years = 0;
double interest = 0;
string principleInput, yearsInput, interestInput;
// User input for Principle amount in dollars
Console.Write("Enter the loan amount, in dollars(0000.00): ");
principleInput = Console.ReadLine();
principle = double.Parse(principleInput);
//Prompt the user to reenter any illegal input
if (principle < 0)
{
Console.WriteLine("The value for the mortgage cannot be a negative value");
principle = 0;
}
// User input for number of years
Console.Write("Enter the number of years: ");
yearsInput = Console.ReadLine();
years = double.Parse(yearsInput);
//Prompt the user to reenter any illegal input
if (years < 0)
{
Console.WriteLine("Years cannot be a negative value");
years = 0;
}
// User input for interest rate
Console.Write("Enter the interest rate(%): ");
interestInput = Console.ReadLine();
interest = double.Parse(interestInput);
//Prompt the user to reenter any illegal input
if (interest < 0)
{
Console.WriteLine("The value for the interest rate cannot be a negative value");
interest = 0;
}
//Calculate the monthly payment
//ADD IN THE .Net function call Math.pow(x, y) to compute xy (x raised to the y power).
double loanM = (interest/1200.0);
double numberMonths = years * 12;
double negNumberMonths = 0 - numberMonths;
double monthlyPayment = principle * loanM/(1 - System.Math.Pow((1 + loanM), negNumberMonths));
//double totalPayment = monthlyPayment;
//Output the result of the monthly payment
Console.WriteLine(String.Format("The amount of the monthly payment is: {0}{1:0.00}", "$", monthlyPayment));
Console.WriteLine();
Console.WriteLine("Press the Enter key to end. . .");
Console.Read();
}
}
}
Все выше работает как и планировалось. Теперь я пытаюсь преобразовать это в веб-приложение ASP.NET с помощью Visual Studio, и я застрял. Мой текущий пользовательский интерфейс, который я установил с тремя ярлыками для основного ввода (с текстовым полем), продолжительностью ссуды (с списком переключателей) и процентной ставкой (с dropdownList).
Моя проблема, с которой я столкнулась, заключается в том, что я пытаюсь получить список радиообмена для моей продолжительности займа (15, 30 или других) в качестве моих выборов. Если пользователь выбирает «Другое», я пытаюсь реализовать текстовое поле для ввода значения в годах. После того, как пользователь выберет свою предполагаемую продолжительность, я хочу, чтобы мой InterestRate был выпадающим списком с 1% -10% в качестве параметров.
У меня также есть кнопка под названием «Рассчитать», где она вычисляет решение с входа пользователя. Если кто-то может привести меня в правильное направление, как подойти к этому. Я совершенно новый для работы с ASP.NET, и я смущен, как успешно преобразовать консольное приложение в проект ASP.NET. Спасибо за помощь!
Моя страница выглядит следующим образом:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Monthly Mortgage Calculator</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Monthly Payment Loan Calculator</h1>
</div>
<asp:Label ID="Label1" runat="server" Text="Please enter the principle amount"> </asp:Label>
<asp:TextBox ID="txtPrinciple" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server"
Text="Please enter the loan duration in years"></asp:Label>
<br />
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True">
<asp:ListItem>15 Years</asp:ListItem>
<asp:ListItem>30 Years</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:RadioButtonList>
<br />
nbsp; &n bsp;
<asp:TextBox ID="txtYears" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Please select the interest rate"> </asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Monthly Payment" />
</form>
</body>
</html>
Опубликовать некоторые из ваших код разметки asp, как выглядит страница –
@Mikey Mouse Код обновлен – DaBulls33
Выглядит хорошо. Вам нужно добавить метод OnClick либо к разметке кнопок, либо по вашему коду. Позади «+ =» В моем решении есть пример, поставьте точку останова, чтобы увидеть, работает ли она –