Minifycode 2020-02-19 Viewed 2.3K times ASP.NET MVC

In this article, you will learn 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

How To Create Body Mass Index (BMI) Calculator in asp.net MVC using c#, 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
public static byte[] CreateHTMLtoPDF(string HtmlString) { var htmlContent = String.Format(HtmlString); var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter(); htmlToPdf.Orientation = NReco.PdfGenerator.PageOrientation.Landscape; //var Orientation = new NReco.PdfGenerator.HtmlToPdfConverter().Orientation=NReco.PdfGenerator.PageOrientation.Landscape; htmlToPdf.Size = NReco.PdfGenerator.PageSize.A4; //htmlToPdf.Zoom = -0.55f; var pageMargin = new NReco.PdfGenerator.HtmlToPdfConverter().Margins; //htmlToPdf.PageHeight= 210; //htmlToPdf.PageWidth = 297; pageMargin.Left = 25; pageMargin.Right = 25; pageMargin.Bottom = 25; pageMargin.Top = 25; var pdfBytes = htmlToPdf.GeneratePdf(htmlContent); byte[] bytes; using (MemoryStream input = new MemoryStream(pdfBytes)) { using (MemoryStream output = new MemoryStream()) { string userpassword = "123";//Change it with User DOB Format dd-MM-yyyy string Ownerpassword = "123";//Change it with whatever owner is wanted PdfReader reader = new PdfReader(input); PdfEncryptor.Encrypt(reader, output, true, userpassword, Ownerpassword, PdfWriter.ALLOW_SCREENREADERS); bytes = output.ToArray(); //Response.ContentType = "application/pdf"; //Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf"); //Response.Cache.SetCacheability(HttpCacheability.NoCache); //Response.BinaryWrite(bytes); //Response.End(); } } return bytes; } <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SendOTP.aspx.cs" Inherits="Shoping_Cart.SendOTP" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>How to Send and Verify OTP On Mobile No Using C# In Asp.Net</title> </head> <body> <form id="form1" runat="server"> <div> Mobile No: <asp:TextBox ID="txtMobileNo" runat="server" Width="200px"></asp:TextBox> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Send OTP" /> <br /> <asp:Label ID="lblMessage" runat="server" Text=""></asp:Label> </div> </form> </body> </html> using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Shoping_Cart { public partial class SendOTP : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { try { Random r = new Random(); string OTP = r.Next(1000, 9999).ToString(); //Send message string Username = "youremail@domain.com"; string APIKey = "YourHash"; string SenderName = "MyName"; string Number = "981111111"; string Message = "OTP code is - " + OTP; string URL = "http://api.minifycode.in/send/?username=" + Username + "&hash=" + APIKey + "&sender=" + SenderName + "&numbers=" + Number + "&message=" + Message; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); StreamReader sr = new StreamReader(resp.GetResponseStream()); string results = sr.ReadToEnd(); sr.Close(); Session["OTP"] = OTP; //Redirect for varification Response.Redirect("VerifyOTP.aspx"); } catch (Exception ex) { lblMessage.Text = ex.Message.ToString(); } } } } <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Verify.aspx.cs" Inherits="Cart.VerifyOTP" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Verify OTP</title> </head> <body> <form id="form1" runat="server"> <div> OTP: <asp:TextBox ID="txtOTP" runat="server" Width="200px"></asp:TextBox> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Verify OTP" /> <br /> <asp:Label ID="lblMessage" runat="server" Text=""></asp:Label> </div> </form> </body> </html> using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Cart { public partial class OTP : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { if (Session["OTP"].ToString() == txtOTP.Text) { lblMessage.Text = "You have enter correct OTP."; Session["OTP"] = null; } else { lblMessage.Text = "Pleae enter correct OTP."; } } } }