Refresh Grid.Mvc data after refresh data

I have a Grid Mvc like this:

    @helper CustomRendering(int id)
{
    @*<button class="btn btn-primary" onclick="location.href='@Url.Action("AcceptRequest", "TableRequest", new { id = id })'"> Accept</button>*@
    <button class="btn btn-primary" onclick="postAccept(@id)" id="@id"> Accept</button>
    <button class="btn btn-danger" onclick="setWindowId(@id)" id="@id">Decline</button>
}
@Html.Grid(Model).Columns(columns =>
                    {                                                
                        columns.Add(c => c.UserName).Titled("Name").Filterable(true);
                        columns.Add(c => c.DateStart).Titled("DateStart");
                        columns.Add(c => c.DateEnd).Titled("DateEnd");
                        columns.Add(c => c.Approved).Titled("Approved");
                        columns.Add(o => o.Id).Encoded(false).Sanitized(false)
                                    .Titled("Action")
                                    .RenderValueAs(o => CustomRendering(o.Id).ToHtmlString());                                           
                    }).WithPaging(10).Sortable(true)

      

And I have a js script like this:

var tempId;        
        function setWindowId(id) {
            $("#dialog").dialog();
            tempId = id;
        }       
        function postMessage() {        
            var message = $('textarea#commentForDecline').val();
            var obj = {};
            obj.mes = $('textarea#commentForDecline').val();
            obj.mes = message;
            obj.id = tempId;

            $.ajax({
                type: "POST",
                url: "/TableRequest/DeclineRequest",            
                data: {'message': obj.mes, 'id': obj.id},
                success: function (msg) {                    
                }
            });       
            $("#dialog").dialog('close');
            $('textarea#commentForDecline').val('');
        }

        function postAccept(id){
            $.ajax({
                type: "POST",
                url: "/TableRequest/AcceptRequest",
                data: {'id': id },
                success: function (msg) {
                }
            });
        }

      

As you can see this js function I am using for buttons, which you can see on the block @helper

. I am just sending two ajax call messages to MVC actions. And I have a problem: the page needs to be refreshed to see any updates. Is there a way to update the Grid MVC after updating the DB?

public virtual ActionResult AcceptRequest(int id)
        {           
            using(var _db = new ApplicationDbContext())
            {
                Shedule shedule = _db.Shedules.SingleOrDefault(x => x.Id == id);
                shedule.IsDirectorApproved = true;
                _db.SaveChanges();
            }
            return RedirectToAction("Index");
        }

        [HttpPost]
        public virtual ActionResult DeclineRequest(string message, int id)
        {
            using (var _db = new ApplicationDbContext())
            {
                Shedule shedule = _db.Shedules.SingleOrDefault(x => x.Id == id);
                shedule.IsDirectorApproved = false;
                shedule.Message = message;
                _db.SaveChanges();
            }
            return RedirectToAction(MVC.TableRequest.ActionNames.Index);
        }

      

+3
jquery ajax model-view-controller grid


source to share


No one has answered this question yet

Check out similar questions:

2245
How do I refresh the page using jQuery?
1567
Converting form data to JavaScript object with jQuery
1300
Transferring data between view controllers
1273
How to handle redirect request after jQuery Ajax call
1061
How can I check if an element is visible after scrolling?
876
Selecting and manipulating CSS pseudo-elements like :: before and :: after using jQuery
853
Element selection by data attribute
736
jQuery how to find element based on data attribute value?
337
jQuery: Return data after ajax call success
1
Collect form data for ajax submission



All Articles
Loading...
X
Show
Funny
Dev
Pics