I have a code similar to the one shown below, and I am wondering if there is a more efficient way to code this method in mvc.
public ActionResult LogViewerFiles([DataSourceRequest] DataSourceRequest request, string testValue, string testValue2)
{
if (string.IsNullOrWhiteSpace(testValue2) && string.IsNullOrWhiteSpace(testValue))
{
return View();
}
if (!string.IsNullOrWhiteSpace(testValue))
{
var fileName = testValue;
var logEntries = LogEntry.ReadLogEntries(fileName);
if (logEntries == null)
{
return JavaScript("Callback()");
}
return Json(logEntries.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
if (testValue2!= null)
{
var resultPath = testValue2;
var logEntriesArch = LogEntry.ReadLogEntries(resultPath);
return Json(logEntriesArch.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
return null;
}
Basically what I am attempting to achieve is to execute different if statements, depending on the value of my arguments. In this case, only one argument will have the information I need to execute the code, and the other argument will always be null. This method is written so all the information gathered can be displayed in a kendo razor grid.
Aucun commentaire:
Enregistrer un commentaire