Scan to open on your phone
Point a camera at the QR code - it opens this exact paste, no app needed.
https://codepastes.com/p01untitledPlain Text
Model
namespace ArithmeticMVC.Models
{
public class Calculator
{
public double Number1 { get; set; }
public double Number2 { get; set; }
public required string Operation { get; set; }
public double Result { get; set; }
}
Contoller
Remove existing code inside HomeController and replace with:
Using Microsoft.AspNetCore.Mvc;
Using ArithmeticMVC.Models;
namespace ArithmeticMVC.Controllers
{
public class HomeController:Controller
{
//GET Method
public IActionResult Index()
{
return View();
}
//POST Method
[HttpPost]
public IActionResult Index(Calculator calc)
{
switch(calc.Operation)
{
case "+":
calc.Result = calc.Number1 + calc.Number2;
break;
case "-":
calc.Result = calc.Number1 - calc.Number2;
break;
case "*":
calc.Result = calc.Number1 * calc.Number2;
break;
case "/":
if (calc.Number2!=0)
{
calc.Result = calc.Number1 / calc.Number2;
}
break;
}
return View(calc);
}
}
}
View
@model ArithmeticMVC.Models.Calculator
<h2>Arithmetic Operations</h2>
<form method="post">
<label>Enter Number1</label><br/>
<input type="number" step="any"asp-for="Number1"/>
<br/><br/>
<label>Enter Number2</label><br/>
<input type="number" step="any"asp-for="Number2"/>
<br/><br/>
<label>Select Operation</label><br/>
<select asp-for="Operation">
<option value="+">Addition</option>
<option value="-">Subtraction</option>
<option value="*">Multiplication</option>
<option value="/">Division</option>
</select>
<br/><br/>
<input type="submit" value="Calculate"/>
</form>
<br/>
@if(Model!=null)
{
<h3>Result=@Model.Result</h3>
}
1,559 chars · codepastes.com