title: How to make simple calculations using model items and an input from a form in ASP.net MVC 3?
body: <p>Am new to programming and ASP.net MVC 3 so don't be surprised by my lack of knowledge on this.. Okay, I want to multiply two decimals, One decimal comes from the form that a user fills and the other decimal comes from the Model class (gets it from the database).</p>
  
  <p>I have two Model classes called RATE &amp; PROJECTMATERIAL . The RATE class has an item called <strong>Amount</strong> that states the amount of a Rate and the PROJECTMATERIAL class has an item <strong>quantity</strong>. The classes are related and i want to be able to say <strong>variable1 = quantity*Rates.amount</strong> and return variable1 to the my Index, Delete, Details views. I don't want to store variable1 to my database but i just want to display in my views.....but i don't know how and where to do it </p>
  
  <p>Code from Project material class..</p>
  
  <pre><code>public class ProjectMaterial
  {
      public int ProjectMaterialID { get; set; }
  
      [Required]
      [Display(Name = "Scope Name")]
      public int? ScopeID { get; set; }
  
      [Required]
      [Display(Name = "Rate Code")]
      public int? RateID { get; set; }
  
      [Required]
      [Display(Name = "Quantity")]
      public decimal Quantity { get; set; }
  
  
      public virtual Scope Scopes { get; set; }
      public virtual Rate Rates { get; set; }
  
  }
  </code></pre>
  
  <p>Code from scope class..</p>
  
  <pre><code>public class Rate
  {
      public int RateID { get; set; }
  
  
      [Required]
      [Display(Name = "Rate Code")]
      public int RateCode { get; set; }
  
      [Required]
      [Display(Name = "Unit")]
      public string Unit { get; set; }
  
      [Required]
      [Display(Name = "Description")]
      public string Description { get; set; }
  
      [Required]
      [Display(Name = "Amount")]
      public decimal Amount { get; set; }
  
      public virtual ICollection&lt;ProjectMaterial&gt; ProjectMaterials { get; set; }
  }
  </code></pre>
  
  <p>Code from project controller class...</p>
  
  <pre><code>public class ProjectMaterialController : Controller
  {
      private ContructorContext db = new ContructorContext();
  
      //
      // GET: /ProjectMaterial/
  
      public ViewResult Index()
      {
          var projectmaterials = db.ProjectMaterials.Include(p =&gt; p.Scopes).Include(p =&gt; p.Rates);
  
          return View(projectmaterials.ToList());
      }
  
  
  
      //
      // GET: /ProjectMaterial/Details/5
  
      public ViewResult Details(int id)
      {
          ProjectMaterial projectmaterial = db.ProjectMaterials.Find(id);
          return View(projectmaterial);
      }
  
      //
      // GET: /ProjectMaterial/Create
  
      public ActionResult Create()
      {
          ViewBag.ScopeID = new SelectList(db.Scopes, "ScopeID", "ScopeName");
          ViewBag.RateID = new SelectList(db.Rates, "RateID", "Unit");
          return View();
      } 
  
      //
      // POST: /ProjectMaterial/Create
  
      [HttpPost]
      public ActionResult Create(ProjectMaterial projectmaterial)
      {
          if (ModelState.IsValid)
          {
              db.ProjectMaterials.Add(projectmaterial);
              db.SaveChanges();
              return RedirectToAction("Index");  
          }
  
          ViewBag.ScopeID = new SelectList(db.Scopes, "ScopeID", "ScopeName", projectmaterial.ScopeID);
          ViewBag.RateID = new SelectList(db.Rates, "RateID", "Unit", projectmaterial.RateID);
          return View(projectmaterial);
      }
  
      //
      // GET: /ProjectMaterial/Edit/5
  
      public ActionResult Edit(int id)
      {
          ProjectMaterial projectmaterial = db.ProjectMaterials.Find(id);
          ViewBag.ScopeID = new SelectList(db.Scopes, "ScopeID", "ScopeName", projectmaterial.ScopeID);
          ViewBag.RateID = new SelectList(db.Rates, "RateID", "Unit", projectmaterial.RateID);
          return View(projectmaterial);
      }
  
      //
      // POST: /ProjectMaterial/Edit/5
  
      [HttpPost]
      public ActionResult Edit(ProjectMaterial projectmaterial)
      {
          if (ModelState.IsValid)
          {
              db.Entry(projectmaterial).State = EntityState.Modified;
              db.SaveChanges();
              return RedirectToAction("Index");
          }
          ViewBag.ScopeID = new SelectList(db.Scopes, "ScopeID", "ScopeName", projectmaterial.ScopeID);
          ViewBag.RateID = new SelectList(db.Rates, "RateID", "Unit", projectmaterial.RateID);
          return View(projectmaterial);
      }
  
      //
      // GET: /ProjectMaterial/Delete/5
  
      public ActionResult Delete(int id)
      {
          ProjectMaterial projectmaterial = db.ProjectMaterials.Find(id);
          return View(projectmaterial);
      }
  
      //
      // POST: /ProjectMaterial/Delete/5
  
      [HttpPost, ActionName("Delete")]
      public ActionResult DeleteConfirmed(int id)
      {            
          ProjectMaterial projectmaterial = db.ProjectMaterials.Find(id);
          db.ProjectMaterials.Remove(projectmaterial);
          db.SaveChanges();
          return RedirectToAction("Index");
      }
  </code></pre>
  
  <p>Thanx in advance guys!! really need your help.</p>