Click here to Skip to main content
15,878,945 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I write index page using bootstrap data table and .net mvc and i want my last column to be redirect button to order details. I filled datatable using ajax/jquery and maked button in this last column. When i click on it nothing happend and i get following error: identifier starts immediately after numeric literal.

I put my code bellow

$(document).ready(function ()
      {
          $('#ordersList').DataTable({
              "ajax": {
              "type" : "GET" ,
              "url" : "@Url.Action("GetData","OrderManager")" ,
              "datatype" : "json"
              },
              "columns":
              [
              { "data" : "CreatedAt" },
              { "data" : "FirstName" },
              { "data" : "Surname" },
              { "data" : "Email" },
              { "data": "OrderStatus" },
              { "data": "Id" , "render" : function ( data ) {
                  return "<a class= 'btn btn-danger' onclick = Menage(" + data + ")> Menage</a>";
                  }}
              ]
          });
      });

  function Menage( id ) {
          var url = '@Url.Action("UpdateOrder", "OrderManager", new { id = "__id__" })';
          window.location.href = url.replace('__id__', id);
  }


Controller name is: OrderManagerController Action is: UpdateOrder
public ActionResult GetData()
        {
            List<Order> data = orderService.GetOrderList();
            return Json( new { data=data}, JsonRequestBehavior.AllowGet);
        }

        public ActionResult UpdateOrder(string Id)
        {
            ViewBag.StatusList = new List<string>() {
                "Order Created",
                "Order Processed",
                "Order Shipped",
                "Order Complete"
            };
            Order order = orderService.GetOrder(Id);
            return View(order);
        }

        [HttpPost]
        public ActionResult UpdateOrder(Order UpdatedOrder, string Id)
        {
            Order order = orderService.GetOrder(Id);
            order.OrderStatus = UpdatedOrder.OrderStatus;
            orderService.UpdateOrder(order);
            return RedirectToAction("Index");
        }


What I have tried:

Replace
return "<a class= 'btn btn-danger' onclick = Menage(" + data + ")> Menage</a>";
with
return "<a class= 'btn btn-danger' onclick = 'Menage(" + data + ")'> Menage</a>";
but nothing happend
Posted
Updated 16-Apr-20 0:42am
Comments
F-ES Sitecore 16-Apr-20 6:00am    
Use the console to find out what line the error occurs on, that should help narrow it down.

1 solution

The fact that you're passing strings to your actions suggests that Id is not a numeric value. You will need to wrap the value in quotes in order to pass it to your function.
JavaScript
{ 
    "data": "Id" , 
    "render" : function ( data ) {
        return '<a class="btn btn-danger" onclick="Menage(\'' + data + '\')">Menage</a>';
    }
}

NB: I suspect you meant to write Manage[^]. At least in English, Menage[^] is not commonly used at all, and never as a verb.
 
Share this answer
 
Comments
Member 12470237 16-Apr-20 7:00am    
Thank you so much for help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900