for eg to total = price* quantity
How to display calculated field in ASP.NET MVC Web Application
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
for eg to total = price* quantity
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 11, 2023, 4:03 AM EST
Hello Suman,
To display a calculated field in an ASP.NET MVC Web Application, you can create a property in your model class to hold the calculated value, and then display it in a view. Here's an example:
Model Class:
public class Order { public decimal Price { get; set; } public int Quantity { get; set; } public decimal Total { get { return Price * Quantity; } } }Controller: In your controller
public class OrderController : Controller { public ActionResult CalculateTotal() { Order order = new Order(); order.Price = 10; order.Quantity = 5; return View(order); } }View: In your view
Thanks
Naimish Makwana