I am working on Asp.net MVC5(Entity Framework) in which :
1: I have one master table (FeeMaster)

2: all fields have default value 0.
3: another table (Basic Details),SELECT TOP (1000) [Id]
,[Name_Department]
,[Father_OrgName]
,[City]
,[Street]
,[Locality]
,[Pincode]
,[PlotNo]
,[District]
,[Tehsil]
,[Village]
,[Ward]
,[KhasraNo]
,[KhewetNo]
,[KhataNo]
,[CompoundWall]
,[LandDevelopment]
,[MeasureGround]
,[MeasureBase]
,[MeasureTotal]
,[NoOfFloor]
,[Floor1]
,[Area1]
,[Floor2]
,[Area2]
,[Floor3]
,[Area3]
,[Floor4]
,[Area4]
,[Floor5]
,[Area5]
FROM [dbname].[dbo].[BasicDetails]
in which if i enter MeasureBase = 700 then its multiply by RateBase i.e. 10 Rs/Sqt similarly if i enter MeasureGround = 700 then its multiply by Rate ground i.e 15 Rs/Sqt, and if i enter Number of floor = 2 then it multiply by RateFloor i.e 20 rs/sqt , as with compundwall = 300 then it multiply by CompundWall i.e 10 Rs/rft and Landscapping 200 then it multiply by 25 Rs/sft, after all the calculation(multiplication and addition) it give value in Measure Total.
How can i use master table and all the calculation

Sachin SinghRank #66 · 26.2K reputationPosted Dec 23, 2022, 2:18 AM EST
You need to do calculation on onchange event of textboxes
Vishal JoshiRank #377 · 6.7K reputationPosted Dec 21, 2022, 4:12 AM EST
Hello,
There can be several wasy to achive this secnario. but, i would suggesst to create Model Structure. Please check below sample code.
Public Class BasicDetails { Public int MeasureGround { get; set; } Public int NoOfFloor { get; set; } // all other property // Declare Parent Model as a property Public FeeMaster feeMaster { get; set; } } Public Class FeeMaster { public double RateBase { get; set; } public NoOfFloorRateBase { get; set; } // all other property }Thank You
Garima BansalRank #1,555 · 1K reputationPosted Dec 21, 2022, 6:30 AM EST
i use viewbag to deal with master table, in actionmethod
public ActionResult Index(FormCollection fomr)
{
ViewBag.RateBase = "";
ViewBag.RateGround = "";
ViewBag.RateFloor = "";
ViewBag.CompoundWall = "";
ViewBag.LandScapping = "";
FeeMaster mastertable = (db.FeeMasters.Where(x => x.Id == 1)).SingleOrDefault();
if (mastertable != null)
{
ViewBag.RateBase = mastertable.RateBase;
ViewBag.RateGround = mastertable.RateGround;
ViewBag.RateFloor = mastertable.RateFloor;
ViewBag.CompoundWall = mastertable.CompoundWall;
ViewBag.LandScapping = mastertable.LandScapping;
}
to get the value.
but next scenrio is :
if i enter MeasureBase = 700 then its multiply by RateBase i.e. 10 Rs/Sqt similarly if i enter MeasureGround = 700 then its multiply by Rate ground i.e 15 Rs/Sqt, and if i enter Number of floor = 2 then it multiply by RateFloor i.e 20 rs/sqt , as with compundwall = 300 then it multiply by CompundWall i.e 10 Rs/rft and Landscapping 200 then it multiply by 25 Rs/sft, after all the calculation(multiplication and addition) it give value in Measure Total.
Vishal JoshiRank #377 · 6.7K reputationPosted Dec 21, 2022, 7:38 AM EST
ViewBag is fine.
Now you need to get data for BasicDetails same as FeeMaster. Please reref below sample code for the same.
public ActionResult Index(FormCollection fomr) { ViewBag.RateBase = ""; ViewBag.RateGround = ""; ViewBag.RateFloor = ""; ViewBag.CompoundWall = ""; ViewBag.LandScapping = ""; FeeMaster mastertable = (db.FeeMasters.Where(x => x.Id == 1)).SingleOrDefault(); if (mastertable != null) { ViewBag.RateBase = mastertable.RateBase; ViewBag.RateGround = mastertable.RateGround; ViewBag.RateFloor = mastertable.RateFloor; ViewBag.CompoundWall = mastertable.CompoundWall; ViewBag.LandScapping = mastertable.LandScapping; } List basicDetailSubTable = (db.BasicDetails).ToList(); var DyObjectsList = new List; dynamic DyObj = new ExpandoObject(); foreach(var item in basicDetailSubTable) { DyObj.MeasureBaseTotalCost = (item.MeasureBase * mastertable.RateBase); DyObj.MeasureGroundTotalCost = (item.MeasureGround * mastertable.RateGround); DyObj.NoOfFloorTotalCost = (item.NoOfFloor * mastertable.RateFloor); DyObjectsList.Add(DyObj); } // Use this viewBag in UI to display total cost data ViewBag.TotalCosts = DyObjectsList; }Another way you can set BasicDetails data in ViewBag Or Strongly type mode and in UI/FronEnd side write multiplication logic to calculate total cost.
Thank you
Garima BansalRank #1,555 · 1K reputationPosted Dec 23, 2022, 2:02 AM EST
Vishal Joshi
this scenario doesnt work
Garima BansalRank #1,555 · 1K reputationPosted Dec 23, 2022, 2:33 AM EST
Sachin Singh
i have two database table one is BasicDetails and other is Feemaster is a master table, so i create this in controller
ViewBag.RateBase = ""; ViewBag.RateGround = ""; ViewBag.RateFloor = ""; ViewBag.CompoundWall = ""; ViewBag.LandScapping = ""; FeeMaster mastertable = (db.FeeMasters.Where(x => x.Id == 1)).SingleOrDefault(); if (mastertable != null) { ViewBag.RateBase = mastertable.RateBase; ViewBag.RateGround = mastertable.RateGround; ViewBag.RateFloor = mastertable.RateFloor; ViewBag.CompoundWall = mastertable.CompoundWall; ViewBag.LandScapping = mastertable.LandScapping; }Then in View, i created hidden fileds for mastertable
Now the scenerio is, if user enter MeasureBase = 700 then its multiply by RateBase i.e. 10 Rs/Sqt similarly if i enter MeasureGround = 700 then its multiply by Rate ground i.e 15 Rs/Sqt, and if i enter Number of floor = 2 then it multiply by RateFloor i.e 20 rs/sqt , as with compundwall = 300 then it multiply by CompundWall i.e 10 Rs/rft and Landscapping 200 then it multiply by 25 Rs/sft, after all the calculation(multiplication and addition) it give value in Measure Total.
Sachin SinghRank #66 · 26.2K reputationPosted Dec 23, 2022, 2:54 AM EST
@Garima, as per your design it is even easier
$("#MeasureBase").change(function(){ $(this).val($(this).val()*parseInt($("#RateBase").val(),10)); });same for other controls.
Sachin SinghRank #66 · 26.2K reputationPosted Dec 23, 2022, 4:41 AM EST
@Garima
for MeasureTotal
you need to sum all textbox values (except one pair obviously all other will be zero, so it won't affect the calculation)
var sumMeasureTotal= parseInt($("#field1").val(),10)+parseInt($("#field1").val(),10)+....so on. $("#MeasureTotal").val(sumMeasureTotal);