@*

    This example demonstrates processing a form in a Razor View using Core MVC.

*@

@{

    Layout = null;

}

 

<html>

<head>

    <meta name="viewport" content="width=device-width" />

    <title>Simple Interest Calculator</title>

</head>

<body>

    <h3>Simple Interest Calculator</h3>

    <hr />

    <h3>

        This example demonstrates processing a form within a Razor View. The form data

        is submitted using an HTTP Post to a Core MVC Controller. The controller accesses the form data

        from the Request.Form["key"] collection.

    </h3>

    <br />

 

    @*

        <form id="frmLoan" action="/Financial/CalculateInterest" method="post">

        This is an alternative form tag that could be used to submit the form.

        This form tag uses simple HTML instead of Microsoft's Tag Helpers.

    *@

 

    @*

        This Razor View's form will automatically postback to the controller that delivered the view.

        The action attribute is used to indicate the controller's action method based on the

        route attribute [HttpPost("CalculateInterest")] used in the controller's class. The

        method attribute indicates that the form data will be sent using an HTTP Post Request.

    *@

    <form asp-controller="Financial" asp-action="CalculateInterest" method="post">

        @*

           Html.Raw() method is used to render a string that contains HTML.

           Otherwise, the string containing HTML in ViewData["Message"] would

           display the HTML code rather than rendering it.

        *@

        <div id="divDisplay">@Html.Raw(ViewData["Message"]) </div>

     

        <table>

            <tr>

                <td>

                    <label>Amount:</label>

                </td>

                <td>

                    <input id="txtAmount" name="txtAmount" type="text" />

                </td>

            </tr>

            <tr>

                <td>

                    <label>Interest Rate:</label>

                </td>

                <td>

                    <input id="txtRate" name="txtRate" type="text" />

                </td>

            </tr>

            <tr>

                <td>

                    <label>Term in years:</label>

                </td>

                <td>

                    <input id="txtTerm" name="txtTerm" type="text" />

                </td>

            </tr>

            <tr>

                <td>

                    <input type="submit" value="Calculate Simple Interest">

                </td>

                <td>

                </td>

            </tr>

        </table>

    </form>

 

</body>

</html>