Controller Code :
public JsonResult GetQuestion()
{
return Json(_questionMasterService.GetAllQuestionMaster(), JsonRequestBehavior.AllowGet);
}
View code
<table id="tb" border="1" cellpadding="0" cellspacing="0" class=" adminContent table-responsive benchQustable"></table>
<script type="text/javascript">
$('#tb').empty().append('<thead class="k-grid-header" ><tr class="" ><th class="k-header" style="width:80%;">Question</th><th class="k-header" style="width:20%;">Answer Type</th></tr></thead>');
$.ajax({
url: '/Barcode/GetQuestion',
type: 'Get',
success: function (data) {
for (var i = 0; i < data.length; i++) {
if (data[i].ControlType == 3)
$('#tb').append('<tr><td>' + data[i].Question + '</td><td><input type="hidden" name="hf" value="' + data[i].Id + '" /><input type="hidden" name="hfct" value="' + data[i].ControlType + '" /><select name="ddl"><option value="0">Select</option><option value="Yes">Yes</option><option value="No">No</option></select><span class="field-validation-error" name="sps"></span></td></tr>');
if (data[i].ControlType == 2)
$('#tb').append('<tr class="k-alt" ><td>' + data[i].Question + '</td><td><input type="hidden" name="hf" value="' + data[i].Id + '" /><input type="hidden" name="hfct" value="' + data[i].ControlType + '" /><input type="text" name="txtc" ><span name="spc" class="field-validation-error"></span></td></tr>');
if (data[i].ControlType == 1)
$('#tb').append('<tr><td>' + data[i].Question + '</td><td><input type="hidden" name="hf" value="' + data[i].Id + '" /><input type="hidden" name="hfct" value="' + data[i].ControlType + '" /><input type="text" name="txt" class="form-control"><span class="field-validation-error" name="spt"></span></td></tr>');
}
}
});
$('#btn').click(function(){
case "2":
var window = $('#BenchTestdv');
if (!window.data('kendoWindow')) {
window.kendoWindow({
modal: true,
title: 'Bench Test Questionaire',
actions: ['Close'],
width: "80%",
scrollable: true,
draggable: false,
resizable: false,
visible: false,
});
}
window.data('kendoWindow').center().open();
$('#tb').find('tr').each(function (i, j) {
$(j).find('td').find("input[name=txtc]").kendoDatePicker();
});
});
$('#btnsave').click(function () {
var answer = "";
var datasave = [];
var mark = 0;
$('#tb').find('tr td').find("[name='spt']").text('');
$('#tb').find('tr td').find("[name='spc']").text('');
$('#tb').find('tr td').find("[name='sps']").text('');
$("[name='spr']").text('');
$('#tb').find('tr').each(function (i, j) {
if (i != 0)
{
if ($(j).find('td').find("input[name='txt']").val() == "")
{
$(j).find('td').find("[name='spt']").text('This field should not blank.');
mark = 1;
}
if ($(j).find('td').find("input[name='txtc']").val() == "") {
$(j).find('td').find("[name='spc']").text('This date field should not blank.');
mark = 1;
}
if ($(j).find('td').find("select[name='ddl']").val() == 0) {
$(j).find('td').find("[name='sps']").text('Please select a answer from the dropdown.');
mark = 1;
}
if ($(j).find('td').find("input[name='hfct']").val() == 1)
answer = $(j).find('td').find("input[name='txt']").val()
else if ($(j).find('td').find("input[name='hfct']").val() == 2)
answer = $(j).find('td').find("input[name='txtc']").val()
else if ($(j).find('td').find("input[name='hfct']").val() == 3)
answer = $(j).find('td').find("select[name='ddl']").val()
datasave.push({ QuestionId: $(j).find('td').find("input[name='hf']").val(), ANSWER: answer });
}
});
if ($("input[name='rb']").is(':checked') == false)
{
$("[name='spr']").text('Please select a status.');
mark = 1;
}
if (mark == 1)
return false;
else
{
$.ajax({
url: '/Barcode/PostAnswer',
data: { EquipmentId: $('#landingPageEquipmentId').val(), lst: datasave, status: $("input[name='rb']:checked").val() },
type: 'Post',
success: function () {
message();
}
});
}
});
function message() {
var kendoWindow = $("<div />").kendoWindow({
title: "Confirm",
resizable: false,
width: "40%",
modal: true
});
kendoWindow.data("kendoWindow")
.content($("#delete-confirmation007").html())
.center().open();
kendoWindow
.find(".delete-confirm")
.click(function () {
kendoWindow.data("kendoWindow").close();
location.href = '/Barcode/TestSummary?EquipmentId=' + $('#landingPageEquipmentId').val();
});
}
$('#btnCancel1').click(function () {
var window = $('#BenchTestdv');
window.data('kendoWindow').close();
});
});
</script>