How to refresh MVC website without calling controller

On page load, my model is passed with the event list log from the computer. I announce the list and then populate it with these logs.

private List<machine_log> _logObjList = new List<machine_log>();

      

which is populated through this:

@helper FillLogMainList()
{
    foreach (IQueryable<machine_log> logType in Model.MachineLogs)
    {
        foreach (var log in logType)
        {
            _logObjList.Add(log);
        }
    }
}

      

These magazines can be of 6 different types. Application, system, security, etc. I just want to show one type in the webgrid. What can I do now. The problem occurs when I have already loaded, say, Application Logs, but I want to click the Security Logs button to now populate the grid with logs like Secutity from the _logObjList I already have.

When I first open the page, by default the "Application Logs" are populated via this function where I pass "application" as a string like:

@helper FillLogList(string type)
{
    _logs.Clear();
    foreach (var log in _logObjList)
    {
        if (log.log_type == type)
        {
            string entry = "";
            if (log.entry_type == "Warning ")
            {
                entry = "http://trycatchgaming.com/temp/warning.png";
            }
            else
            {
                entry = "http://trycatchgaming.com/temp/error.png";
            }
            var newLine = new SingleLog
            {
                EntryType = entry,
                Message = log.event_id + "#" + log.message,
                Source = log.source,
                EventId = log.event_id,
                LogId = log.id,
                EntryTime = log.entry_time
            };
            _logs.Add(newLine);
        }
    }
}

      

Now I have a list for _logs in which I populate the webgrid, which is part of the normal "body" of the page inside a div:

<div id="grid" style="padding: 0; overflow-y: scroll; height: 500px; width: 100%">
                @obj = new WebGrid(source: _logs, defaultSort: "EntryTime", ajaxUpdateContainerId: "grid", rowsPerPage: 200000);

                @obj.GetHtml(
                    tableStyle: "webgrid-table",
                    htmlAttributes: new { id = "MainTable" },
                    headerStyle: "webgrid-header",
                    //footerStyle: "webgrid-footer",
                    alternatingRowStyle: "webgrid-alternating-row",
                    selectedRowStyle: "webgrid-selected-row",
                    rowStyle: "webgrid-row-style",
                    //mode: WebGridPagerModes.All,
                    columns: obj.Columns(
                        obj.Column(columnName: "EntryType", header: "Event Type", format:@<img src="@item.EntryType" />),
                        obj.Column(columnName: "EntryTime", header: "Event Time"),
                        obj.Column(columnName: "Source", header: "Source"),
                        obj.Column(columnName: "EventId", header: "Event Id"),
                        obj.Column(columnName: "LogId", header: "Log Id"),
                        obj.Column(header: "All", style: "labelcolumn", format: @<text><input class="check-box" tag="check-box" id="assignChkBx" name="Message" type="checkbox" value="@item.Message" /></text>)
                        )
                    )
            </div>

      

So my question boils down to the fact that I know how to clear and create a new list of logs and everything, but I have no idea how to apply that to a grid. Ideally, I could just clear the log list, fill it with security logs, and then update the grid, which will now be filled with security logs. Repeat rinsing.

However, there doesn't seem to be a built-in method for handling data in this way. All examples I can find want me to go back to the controller, get more data, and populate the grid through some partial view. HOWEVER, I already have all the data, and I would rather not create additional queries and loads in order to get the data I already have.

+3


source to share


1 answer


create a separate mesh for each type. And when clicking a button of this type, fill in the corresponding type data in the grid. and keep some track type loaded. And if a different type of button is clicked, hide the previous mesh and load the new type data into another mesh. This reduces the load on the data.



0


source







All Articles