Ramco Ramco

Ramco Ramco

  • 440
  • 3.4k
  • 529.4k

Edit & Add using Partial View

Jun 16 2021 7:50 AM

Hi

    When i click on Add/Update button below Partial View is called. I want when clicked on Updat Button then it should display values .

If Add then all should be Blank,

                    <button type="button" id="btnAdd" class="btn btn-primary"  float-right onclick="clearTextBox();"> <i class="fa fa-plus"></i> Add New Location</button><br /><br />
********************************************************************************

@foreach (var item in Model.Locations)
                            {
                                <tr>
                                    <td>
                                        @Html.DisplayFor(model => item.Id)
                                    </td>
                                    <td>
                                        @Html.DisplayFor(model => item.Description)
                                    </td>
                                    <td>
                                        <a class='btn btn-primary btn-sm' id='btnEdit'><i class='fa fa-pencil'></i> Edit </a>

                                     </td>

</tr>

}

@model MyApplication.Models.Location

<html>
    <body>
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @*@Html.HiddenFor(model => model.Id)*@

        <div class="form-group">
            @Html.LabelFor(model => model.Id, htmlAttributes: new { @class = "control-label col-md-3" })
            <div class="col-md-5">
                @Html.EditorFor(model => model.Id, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Id, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-3" })
            <div class="col-md-9">
                @Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.GstStateCode, htmlAttributes: new { @class = "control-label col-md-3" })
            <div class="col-md-5">
                @Html.EditorFor(model => model.GstStateCode, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.GstStateCode, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.GstStateName, htmlAttributes: new { @class = "control-label col-md-3" })
            <div class="col-md-9">
                @Html.EditorFor(model => model.GstStateName, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.GstStateName, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.GstNo, htmlAttributes: new { @class = "control-label col-md-3" })
            <div class="col-md-5">
                @Html.EditorFor(model => model.GstNo, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.GstNo, "", new { @class = "text-danger" })
            </div>
        </div>
    </body>
</html>

*************************************************************************

 $('body').on('click', '[id*=btnAdd]', function () {
        $(".modal-title").html("Add new location");
        $('#myModal').modal('show');
    });

    $(document).on('click', '[id*=btnEdit]', function () {
        $(".modal-title").html("Update");
        $('#myModal').modal('show');
    });
 

Thanks


Answers (4)