Hi
I have 1 Partial View. I want that same Partial View should be used for Add & Edit.
<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 />
Index View
*************
<table class="table table-striped table-hover" id="tblLocation" style="width:100%"><thead>
<tr>
<th>@Html.DisplayNameFor(model => model.Location.Id)</th>
<th>@Html.DisplayNameFor(model => model.Location.Description)</th>
<th>Action</th>
</tr>
</thead>
@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>
}
</table>
@using (Html.BeginForm("CreateEdit", "Location", FormMethod.Post,new { @id = "locationFormId", @class = "form-horizontal", role = "form" }))
{
<input type="hidden" id="hfAU" name="hfAU" value="A"/>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
@*<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span>Close</button>*@
<h4 class="modal-title"></h4>
</div>
<div class="modal-body">
@Html.Partial("_CreateEdit",Model.Location)
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Save Changes</button>
</div>
</div>
</div>
</div>
}
Partial View
@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>
</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