Hi
I have below Index View
@using (Html.BeginForm("CreateEdit", "Customer", FormMethod.Post))
{
@Html.AntiForgeryToken()
}
******************************** JAVASCRIPT
$('body').on('click', '[id*=btnEdit]', function () {
hfAU = "U";
var data = $(this).parents('tr').find('td');
var Id = data.eq(0).html();
$('#hfId').val(Id);
var url = "/Customer/CreateEdit?Id=" + Id;
$("#myModalBody").load(url, function () {
$(".modal-title").html("Update");
$("#myModal").modal("show");
});
});
********************************************* DATA ANNOTATION
public class Customer
{
//private string _isactive = "Y";
public Customer()
{
CreatedOn = DateTime.Now;
//LastUpdatedOn = DateTime.Now;
}
[Key]
[Required(ErrorMessage = "Id cannot be Blank. Max length should be less than or equal to 20."), MaxLength(20)]
//[RegularExpression(@"^[ a-zA-Z\s]$", ErrorMessage = "Special Characters not allowed")]
[Display(Name = "Id")]
[Remote("IsExist", "Customer", ErrorMessage = "Id already exists")]
public string Id { get; set; }
[Display(Name = "Description")]
[DataType(DataType.Text)]
[Required(ErrorMessage = "Customer Name cannot be Blank. Max length should be less than or equal to 50"), MaxLength(50)]
public string Description { get; set; }
[Display(Name = "Active")]
public bool IsActive { get; set; }
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime CreatedOn { get; set; }
}
Sachin SinghPosted Jun 18, 2021, 11:45 AM
Ramco RamcoPosted Jun 18, 2021, 11:40 AM
Hi Sachin
I get this error now - Uncaught TypeError: $(...).modal is not a function
JavaScript
$('body').on('click', '[id*=btnAdd]', function () {
$('#IsActive').attr('checked', 'checked').attr("disabled", true);
var Id = "";
var url = "/Customer/CreateEdit?Id=" + Id;
$("#myModalBody").load(url, function () {
$(".modal-title").html("Add");
$("#myModal").modal("show");
});
});
**************************************************************
Partial View
@model MyApplication.Models.Customer
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Id, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Id, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Id, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.IsActive, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.IsActive)
@Html.ValidationMessageFor(model => model.IsActive, "", new { @class = "text-danger" })
Sachin SinghPosted Jun 18, 2021, 11:21 AM
Ramco RamcoPosted Jun 18, 2021, 11:19 AM
Hi Sachin
I have these files in Main Layout file
Thanks
Sachin SinghPosted Jun 18, 2021, 11:15 AM
Ramco RamcoPosted Jun 18, 2021, 11:13 AM
Hi Sachin
Partial View
@model MyApplication.Models.Customer
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Id, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Id, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Id, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.IsActive, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.IsActive)
@Html.ValidationMessageFor(model => model.IsActive, "", new { @class = "text-danger" })
Sachin SinghPosted Jun 18, 2021, 11:09 AM