Can you suggest me a solution?
Im trying to display a kendo.grid after clicking submit. I attached a screenshot so you can understand what Im trying to do.
After filling in the information and click submit, I want the information to be displayed below but unfortunately nothing change after I click submit. Only the content in else is displayed
This is my code in view
<script>
$(document).ready(function () {
$("#form").kendoForm({
validatable: { validationSummary: true },
orientation: "horizontal",
formData: ...,
items: ...,
submit: function (ev) {
$.ajax({
type: "POST",
url: RootUrl+"Issue/ReportIssue",
});
}
});
$("#grid").kendoGrid({
dataSource: {
data: [
@if (ViewBag.ReportResult != null)
{
foreach (var item in ViewBag.ReportResult)
{
@: { col1: '@item.ISSUE_NUM', col2: '@item.PRIORITY', col3: '@item.MODULE', col4: '@item.DESCRIPTION', col5: '@item.REPORTED_DATE', col6: '@item.ISSUE_RESOLUTION', col7: '@item.RESPOND_DATE', col8: '@item.ACTION_TAKEN', col9: '@item.RESOLVED_DATE', col10: '@item.STATUS' },
}
} else
{
@: { col1: 'fdfd', col2: 'fd', col3: 're', col4: 'gf', col5: 'hg', col6: 'hy', col7: 'hg', col8: 'jh', col9: 'yt', col10: 'hg' },
}
],
pageSize: 10
},
sortable: true,
pageable: ...,
groupable: true,
filterable: true,
// columnMenu: true,
reorderable: true,
resizable: true,
selectable: "multiple, row",
columns: ...
});
});
Here is my controller. I commented a line in the sql statement(line 24 from bottom). Just ignore that as I dont want to carry two problems at the same time.
[HttpGet]
public ActionResult ReportIssue()
{
if (Session["User_Name"] == null)
return RedirectToAction("Login", "Account");
else
{
ViewBag.ValidationErrorMsg = "";
ViewBag.ReportResult = null;
SetUserViewBag();
return View();
}
}
[HttpPost]
public ActionResult ReportIssue(string application, string environment, string DateFrom, string DateTo)
{
if (Session["User_Name"] == null)
return RedirectToAction("Login", "Account");
else
{
ViewBag.ValidationErrorMsg = "";
string get_report_issue = "select " +
"i.ISSUE_NUM, " +
"i.PRIORITY, " +
"i.MODULE, " +
"CONCAT(i.TITLE, CHAR(13), CHAR(10), i.DESCRIPTION) AS DESCRIPTION, " +
"CONVERT(VARCHAR(20), i.CREATED_DATE, 103)AS REPORTED_DATE, " + //dd / mm / yyyy
"CONCAT(i.ISSUE_TYPE, CHAR(13), CHAR(10), i.ISSUE_CATEGORY, CHAR(13), CHAR(10), i.ISSUE_RESOLUTION) as ISSUE_RESOLUTION, " +
"CONVERT(VARCHAR(20), " +
"( " +
"select " +
"min(MODIFIED_DATE) " +
"from NEPS.dbo.WEBGIS_ISSUE_LOG " +
"where " +
"i.issue_num = issue_num " +
"and FIELD = 'STATUS' " +
"and OLD_VALUE = 'NEW'),103 " +
") as RESPOND_DATE, " + //dd / mm / yyyy
"STUFF( " +
"( " +
"SELECT " +
"',' + a.NEW_VALUE " +
"FROM NEPS.dbo.WEBGIS_ISSUE_LOG a " +
"WHERE " +
"a.ISSUE_NUM = i.ISSUE_NUM " +
"ORDER BY " +
"a.NEW_VALUE FOR XML PATH('')), 1, LEN(','), CHAR(13) " +
") AS ACTION_TAKEN, " +
"CONVERT(VARCHAR(20), ISNULL( " +
"( " +
"select " +
"max(MODIFIED_DATE) " +
"from NEPS.dbo.WEBGIS_ISSUE_LOG " +
"where " +
"i.issue_num = issue_num " +
"and FIELD = 'STATUS' " +
"and NEW_VALUE = 'RESOLVED' " +
"), " +
"( " +
"select " +
"max(MODIFIED_DATE) " +
"from NEPS.dbo.WEBGIS_ISSUE_LOG " +
"where " +
"i.issue_num = issue_num " +
"and FIELD = 'STATUS' " +
"and NEW_VALUE = 'CLOSED' " +
") " +
") , 103) AS RESOLVED_DATE, " +
"i.STATUS " +
"FROM NEPS.dbo.WEBGIS_ISSUE i " +
"LEFT JOIN NEPS.dbo.WEBGIS_ISSUE_LOG C " +
"ON i.ISSUE_NUM = C.ISSUE_NUM " +
"where " +
"(C.FIELD = 'REMARKS' or C.FIELD = 'STATUS') " +
//"AND(C.MODIFIED_DATE between " + Convert.ToDateTime(DateFrom).ToString() + " and " + Convert.ToDateTime(DateTo).ToString() + ") " +
"AND(i.APPLICATION = '" + application + "' OR 'ALL' = '" + application + "' ) " +
"AND(i.ENVIRONMENT = '" + environment + "' OR 'ALL' = '" + environment + "' ) " +
"group by " +
"i.ISSUE_NUM, " +
"i.PRIORITY, " +
"i.MODULE, " +
"i.TITLE, " +
"i.DESCRIPTION, " +
"i.CREATED_DATE, " +
"i.ISSUE_TYPE, " +
"i.ISSUE_CATEGORY, " +
"i.ISSUE_RESOLUTION, " +
"i.STATUS";
var listReportIssue= db.Database.SqlQuery<ReportIssue>(get_report_issue).ToList();
return Json(new
{
Success = true,
ListData = listReportIssue
}, JsonRequestBehavior.AllowGet);
}
}
I see that the syntax is correct, but the ViewBag.ReportResult is always null. This is why it always goes to the dummy data and renders that row.
In the controller pasted the only usage of the ViewBag.ReportResult key is being set to null in the GET action. In the POST action, it is never set to a collection or a value different than null. Unless I am missing something obvious here.