How To Create Body Mass Index (BMI) Calculator in asp.net MVC using c#

How To Create Body Mass Index (BMI) Calculator in asp.net MVC using c#

In this post, how can you develop BMI Calculator in asp.net MVC using c#

BMI calculator source code in c#, BMI calculator visual studio code

 [HttpGet]
        public JsonResult BMICalculatorResult(string ddlHeight, string txtHeight, string txtWeight, string rdbGender)
        {
            var list = new List<dynamic>();
            try
            {
                if (!string.IsNullOrEmpty(txtHeight) && !string.IsNullOrEmpty(txtWeight) && !string.IsNullOrEmpty(ddlHeight))
                {
                    Double height = Convert.ToDouble(txtHeight.Replace("'", ""));
                    string[] splitFeet = height.ToString().Split('.');
                    if (ddlHeight.Replace("'", "") == "Inches")
                    {
                        height = height * 2.54;
                    }
                    else if (ddlHeight.Replace("'", "") == "Feet")
                    {
                        var int_number = splitFeet[0];
                        var float_number = splitFeet[0];
                        if (splitFeet.Length == 1)
                        {
                            int_number = splitFeet[0];
                            float_number = "0";
                        }
                        else
                        {
                            int_number = splitFeet[0];
                            float_number = splitFeet[1];
                        }


                        //double int_number = height - float_number1;
                        double inch = Convert.ToDouble(int_number) * 12;
                        double inch1 = inch + Convert.ToDouble(float_number);
                        height = inch1 * 2.54;

                    }
                    Double weight = Convert.ToDouble(txtWeight.Replace("'", ""));
                    if (weight > 0 && height > 0)
                    {
                        Double finalBmi = weight / ((height / 100) * (height / 100));
                        ViewBag.txtYourEmi = Math.Round(finalBmi, 2).ToString();
                        string MF = rdbGender.Replace("'", "");


                        if (finalBmi < 19 && MF == "FEMALE")
                        {
                            ViewBag.lblMessage = "That you are too thin.";
                            // lblMessage.ForeColor = System.Drawing.Color.Red;
                            double fin = 19 - finalBmi;
                            Double finalBmi1 = finalBmi + fin;
                            weight = 19 * ((height / 100) * (height / 100));
                            Double Weight2 = 24 * ((height / 100) * (height / 100));
                            ViewBag.lblIdealWeight1 = Math.Round(weight, 2).ToString() + "  KG  ";
                            ViewBag.lblIdealWeight2 = Math.Round(Weight2, 2).ToString() + "  KG  ";



                        }
                        if (finalBmi >= 19 & finalBmi <= 24 & MF == "FEMALE")
                        {
                            ViewBag.lblMessage = "That you are healthy.";
                            //lblMessage.ForeColor = System.Drawing.Color.Green;

                            weight = 19 * ((height / 100) * (height / 100));
                            Double Weight2 = 24 * ((height / 100) * (height / 100));
                            ViewBag.lblIdealWeight1 = Math.Round(weight, 2).ToString() + "  KG  ";
                            ViewBag.lblIdealWeight2 = Math.Round(Weight2, 2).ToString() + "  KG  ";
                        }
                        if (finalBmi > 24 & MF == "FEMALE")
                        {

                            ViewBag.lblMessage = "That you have overweight.";
                            //ViewBag.lblMessage.ForeColor = System.Drawing.Color.Red;
                            double fin = finalBmi - 24;
                            Double finalBmi1 = finalBmi + fin;
                            weight = 19 * ((height / 100) * (height / 100));
                            Double Weight2 = 24 * ((height / 100) * (height / 100));
                            ViewBag.lblIdealWeight1 = Math.Round(weight, 2).ToString() + "  KG  ";
                            ViewBag.lblIdealWeight2 = Math.Round(Weight2, 2).ToString() + "  KG  ";

                        }


                        if (finalBmi < 20 && MF == "MALE")
                        {
                            ViewBag.lblMessage = "That you are too thin.";
                            //lblMessage.ForeColor = System.Drawing.Color.Red;
                            double fin = 20 - finalBmi;
                            Double finalBmi1 = finalBmi + fin;
                            weight = 20 * ((height / 100) * (height / 100));
                            Double Weight2 = 25 * ((height / 100) * (height / 100));
                            ViewBag.lblIdealWeight1 = Math.Round(weight, 2).ToString() + "  KG  ";
                            ViewBag.lblIdealWeight2 = Math.Round(Weight2, 2).ToString() + "  KG  ";
                        }
                        if (finalBmi >= 20 && finalBmi <= 25 && MF == "MALE")
                        {

                            ViewBag.lblMessage = "That you are healthy.";
                            //lblMessage.ForeColor = System.Drawing.Color.Green;
                            weight = 20 * ((height / 100) * (height / 100));
                            Double Weight2 = 25 * ((height / 100) * (height / 100));
                            ViewBag.lblIdealWeight1 = Math.Round(weight, 2).ToString() + "  KG  ";
                            ViewBag.lblIdealWeight2 = Math.Round(Weight2, 2).ToString() + "  KG  ";

                        }
                        if (finalBmi > 25 && MF == "MALE")
                        {
                            ViewBag.lblMessage = "That you have overweight.";
                            //lblMessage.ForeColor = System.Drawing.Color.Red;
                            double fin = finalBmi - 25;
                            Double finalBmi1 = finalBmi + fin;
                            weight = 20 * ((height / 100) * (height / 100));
                            Double Weight2 = 25 * ((height / 100) * (height / 100));
                            ViewBag.lblIdealWeight1 = Math.Round(weight, 2).ToString() + "  KG  ";
                            ViewBag.lblIdealWeight2 = Math.Round(Weight2, 2).ToString() + "  KG  ";
                        }
                    }
                    else
                    {

                        ViewBag.lblMessage = "Please Fill correct values";
                        //lblMessage.ForeColor = System.Drawing.Color.Red;

                    }
                }
                else
                {
                    ViewBag.lblMessage = "Please Fill correct values";
                }
            }
            catch
            { }
            list.Add(new { txtYourBmi = ViewBag.txtYourEmi, lblMessage = ViewBag.lblMessage, lblIdealWeight1 = ViewBag.lblIdealWeight1, lblIdealWeight2 = ViewBag.lblIdealWeight2 });
            return Json(list.SingleOrDefault(), JsonRequestBehavior.AllowGet);
        }

in cshtml page

<article style="margin-bottom:20px;">
            <div class="card">

                <div class="card-body">
                    <div class="row">
                        @*<form action="/tools/BMI-calculator" method="post" enctype="multipart/form-data">*@
                        <div class="form-group col-md-3">
                            <div style="color:red">@ViewBag.lblMessage</div>
                            <label for="txtHeight">Height (in in/cm/ft)</label>
                            <select name="ddlHeight" id="ddlHeight" class="form-control" required="true">
                                <option value="">Height Type</option>
                                <option value="CM">Centimeter(CM.)</option>
                                <option value="Inches">Inches</option>
                                <option value="Feet">Feet</option>
                            </select>
                        </div>
                        <div class="form-group col-md-2">
                            <label for="txtHeight">Height</label>
                            <input name="txtHeight" type="text" id="txtHeight" class="form-control" required>
                        </div>
                        <div class="form-group col-md-3">
                            <label for="txtWeight">Weight (in Kg)</label>
                            <input name="txtWeight" type="number" id="txtWeight" class="form-control" required>
                        </div>

                        <div class="form-group col-md-4">
                            <label for="rdbGender">Gender </label>
                            <div class="form-inline" style="color: #000;">

                                <table id="rdbGender" class="form-control rbl" border="0" style="margin-top:4px;">
                                    <tbody>
                                        <tr>
                                            <td><input id="rdbGender_0" type="radio" name="rdbGender" value="MALE" checked="checked">MALE</td>
                                            <td><input id="rdbGender_1" type="radio" name="rdbGender" value="FEMALE">FEMALE</td>
                                        </tr>
                                    </tbody>
                                </table>


                            </div>
                        </div>
                        <input type="submit" name="btnBMICalCulate" value="Calculate" id="btnBMICalCulate" class="btn btn-lg btn-primary pull-center">
                        @*</form>*@
                    </div>
                    <br>
                    <table class="table table-bordered table-striped" width="100%" id="tbl_BMI_details">
                        <tr class="bg-primary text-light text-center"><th colspan="2"><h3>Calculated BMI Results</h3></th></tr>
                        <tr><td><strong>Your BMI: </strong></td><td><strong><span class="text-primary" id="txtYourBmi"></span></strong></td></tr>
                        <tr><td><strong>Health status: </strong></td><td><strong><span class="text-primary" id="lblMessage"> </span></strong></td></tr>
                        <tr><td><strong>Your Ideal body weight: </strong></td><td><strong><span class="text-primary" id="lblIdealWeight1"></span></strong></td></tr>

                    </table>
                    <table class="table dtableheading table-hover table-striped table-bordered time">
                        <tbody>
                            <tr>
                                <td class="txt">Health status </td>
                                <td class="txt"> BMI range</td>
                            </tr>
                            <tr>
                                <td class="txt">under weight </td>
                                <td class="txt">  &lt;18.5</td>
                            </tr>
                            <tr>
                                <td class="txt">normal weight    </td>
                                <td class="txt"> 18.5-  23</td>
                            </tr>
                            <tr>
                                <td class="txt">over weight  </td>
                                <td class="txt"> 23 - 25</td>
                            </tr>
                            <tr>
                                <td class="txt">obese</td>
                                <td class="txt">  &gt;25</td>
                            </tr>


                        </tbody>
                    </table>
                    <div style="overflow-x:auto;">
                        <table class="table dtableheading table-hover table-striped table-bordered time">
                            <tbody>
                                <tr>
                                    <td height="20" colspan="5" bgcolor="#EBEBEB"><p class="style3"><strong>&nbsp;&nbsp;</strong>BMI Notation Chart </p></td>
                                </tr>
                                <tr>
                                    <td height="20" bgcolor="f9f9f9"><p class="style3"><strong>&nbsp;&nbsp;</strong>Age Group </p></td>
                                    <td height="20" bgcolor="f9f9f9"><p class="style3"><strong>&nbsp;&nbsp;</strong>Recommended </p></td>
                                    <td height="20" bgcolor="f9f9f9"><p class="style3"><strong>&nbsp;&nbsp;</strong>Overweight </p></td>
                                    <td height="20" bgcolor="f9f9f9"><p class="style3"><strong>&nbsp;&nbsp;</strong>Obese </p></td>
                                    <td height="20" bgcolor="f9f9f9"><p class="style3"><strong>&nbsp;&nbsp;</strong>Extremely Obese </p></td>
                                </tr>
                                <tr>
                                    <td height="20" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>under 17</p></td>
                                    <td height="20" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>15-20</p></td>
                                    <td height="20" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>21+</p></td>
                                    <td height="20" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>26+</p></td>
                                    <td height="20" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>34+</p></td>
                                </tr>
                                <tr>
                                    <td height="20" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>under 35</p></td>
                                    <td height="20" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>18-24</p></td>
                                    <td height="20" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>25+</p></td>
                                    <td height="20" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>30+</p></td>
                                    <td height="20" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>40+</p></td>
                                </tr>
                                <tr>
                                    <td height="20" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>35 and over</p></td>
                                    <td height="20" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>19-26</p></td>
                                    <td height="20" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>27+</p></td>
                                    <td height="20" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>30+</p></td>
                                    <td height="20" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>40+</p></td>
                                </tr>
                                <tr>
                                    <td height="20" colspan="5" bgcolor="f9f9f9"><p class="style4"><strong>BMI values below 19 for men and 18 for women indicate an    underweight condition.</strong> </p></td>
                                </tr>
                                <tr>
                                    <td height="20" bgcolor="f9f9f9"></td>
                                    <td height="20" bgcolor="f9f9f9"></td>
                                    <td height="20" bgcolor="f9f9f9"></td>
                                    <td height="20" bgcolor="f9f9f9"></td>
                                    <td height="20" bgcolor="f9f9f9"></td>
                                </tr>
                                <tr>
                                    <td height="20" colspan="5" bgcolor="#EBEBEB"><p class="style4"><strong>&nbsp;&nbsp;Calorie Table</strong> </p></td>
                                </tr>
                                <tr>
                                    <td height="20" colspan="2" bgcolor="f9f9f9"><p align="left" class="style4"><strong>&nbsp;&nbsp;Exercise</strong> </p></td>
                                    <td height="20" colspan="3" bgcolor="f9f9f9"><p align="left" class="style4"><strong>&nbsp;&nbsp;Approximate Calories Burned</strong> </p></td>
                                </tr>

                                <tr>
                                    <td height="20" colspan="2" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>Walking (brisk)</p></td>
                                    <td height="20" colspan="3" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>100 calories burned    per mile</p></td>
                                </tr>
                                <tr>
                                    <td height="20" colspan="2" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>Jogging</p></td>
                                    <td height="20" colspan="3" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>120 calories burned    per mile</p></td>
                                </tr>
                                <tr>
                                    <td height="20" colspan="2" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>Swimming</p></td>
                                    <td height="20" colspan="3" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>100 calories burned    in 20 minutes</p></td>
                                </tr>
                                <tr>
                                    <td height="20" colspan="2" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>Bicycling (easy    pace)</p></td>
                                    <td height="20" colspan="3" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>100 calories burned    in 20 minutes</p></td>
                                </tr>
                                <tr>
                                    <td height="20" colspan="2" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>Aerobic exercise to    music</p></td>
                                    <td height="20" colspan="3" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>100 calories burned in    20 minutes</p></td>
                                </tr>
                                <tr>
                                    <td height="20" colspan="2" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>Gardening (vigorous)</p></td>
                                    <td height="20" colspan="3" bgcolor="f9f9f9"><p class="style4"><strong>&nbsp;&nbsp;</strong>100 calories burned    in 30 minutes</p></td>
                                </tr>
                            </tbody>
                        </table>
                        <div class="row">
                            <div class="card">
                                <div class="card-body">
                                    <div class="form-row col-md-12">
                                        <div class="form-group col-md-4">
                                            <img src="/images/BMI-Calculator.jpg" alt="BMI Calculator" style="max-height:133px;">
                                        </div>
                                        <div class="form-group col-md-8">
                                            <h1 class="h3">What is a BMI calculator?</h1>
                                            <p style="text-align:justify">Today the busy life scenario everyone has no time to make healthy food so they just go to the market and take some fast food as a breakfast, lunch, and dinner which increase the <b>Standard Body Mass Index</b>. According to the <b>National Institutes of Health (NIH)</b> that "A BMI of less than 18.5 means that a person is underweight. A <b>Body Mass Index</b> of between 18.5 and 24.9 is ideal. If it between 25 and 29.9 is overweight." So it should be necessary to take help of BMI Calculator for maintaining good health.</p>
                                        </div>
                                    </div>
                                    <h1 class="h3">How BMI (Body Mass Index) calculator Help you?</h1>
                                    <p style="text-align:justify">The <b>BMI (Body Mass Index) Calculator</b> helps you to check the current status of your body to take precaution before you got a heavyweight or losing weight, so everyone needs to take the help of a <b>Body Mass Index or BMI Calculator</b> to measure this for good health to reduce obesity.</p>
                                    <h1 class="h3">What is the ideal BMI for a woman? And how BMI calculator can help you?</h1>
                                    <p style="text-align:justify">The healthy BMI range is the same for men and women, so the results apply to both. <b>The healthy traditional weight vary could be a </b> BMI between eighteen.5 and 24.9. A body mass index of 22 is in the middle of that range. With the help of <b>BMI Calculator</b>, you can measure your current status of your Body Mass Index (BMI).</p>
                                    <h2>How BMI Calculator is helpful for your kids?</h2>
                                    <p style="text-align:justify">The BMI Calculator follows a <b>model for kids</b> that, If your kid is a 14-year-old kid who is 5ft 3 inches tall and gauges 120 pounds, for instance, his BMI is 21.3 which places him in the 76th percentile. This BMI figure shows that he is at a sound weight because the correct range is somewhere in the range of 90 and 128 pounds, in this case, you can take help of the BMI calculator. Because it not only shows the Body Mass Index also gives you a diet chart for your kids.</p>
                                    <h1 class="h3">How can I reduce my weight?</h1>
                                    <ul>
                                        <li><b>Here area unit ten tips to thin even faster:</b></li>
                                        <li>1. Eat a high-protein breakfast.</li>
                                        <li>2. Avoid sugary drinks and fruit juice.</li>
                                        <li>3. Drink water a half hour before meals.</li>
                                        <li>4. Drink coffee or tea.</li>
                                        <li>5. Eat mostly whole, unprocessed foods.</li>
                                        <li>6. Eat your food slowly.</li>
                                        <li>7. Weigh yourself every day.</li>
                                        <li>8. Get a good night's sleep, every night.</li>
                                        <li>9. Choose weight loss-friendly foods.</li>
                                        <li>10. Eat soluble fiber.</li>
                                    </ul>
                                    <p style="text-align:justify">By using the <b>BMI Calculator</b> you can take help for maintaining the <b>Body Mass Index.</b></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </article>

bmi calculator code in asp net

c program to calculate bmi using 2d array

bmi calculator source code in c#

write a program that calculates and displays a person's body mass index (bmi)

write a program that calculates and displays a person's body mass index - python

c# body mass index

bmi calculator visual studio code

bmi function in c programming

2020-02-19