0

I have MVC Grid and i want to render a actionlink so that onclick of the link a javascript function should call.I have tried this code but its not working please help here.. not working means on view click the page is without layout

enter image description hereenter image description here

@Html.Grid(Model).Named("receipt").Columns(columns =>
{


    columns.Add(c => c.PaymentDate).Format("{0:dd/MM/yyyy}").Titled("Date").Filterable(true);

    columns.Add(c => c.CustomerName).Titled("Customer").Filterable(true);

    columns.Add(c => c.TotalAmountApplied).Titled("Amount").Filterable(true);


    columns.Add().Encoded(false).Sanitized(false).Titled("View").Filterable(false).RenderValueAs(o => Html.ActionLink("see", null,null, new { onclick = "ViewReceipts('"+o.PayReceved_ID+"');" }));


}).WithPaging(@ViewBag.paging).Sortable(true)



<script type="text/javascript">

    function ViewReceipts(recId)
    {
      //do something here
    }

</script>
  • not working means what? It doesn't render the onclick code? It renders incorrectly? Or the code's there but it doesn't execute? Have you checked the page source? Have you checked your console for errors? Have you set breakpoints in the JS to see if your function gets executed or not? Please clarify and explain what debugging you've done so far. – ADyson Jun 07 '18 at 08:50
  • not working means, onpaging the page is excluded by layout – sumit.spider Jun 07 '18 at 08:54
  • Huh? What does that have to do with your question? Your question was about rendering some Javascript onto a link element. How does that lead to anything to do with paging? What do you mean "excluded" anyway? Also can you please answer my questions about debugging. – ADyson Jun 07 '18 at 08:56
  • sorry for not clarifying the things..i have updated the question please see – sumit.spider Jun 07 '18 at 09:05
  • I suspect the "click" event of the link is also navigating the page at the same time as running your Javascript. Try putting `return false;` at the end of your ViewReceipts Javascript function. – ADyson Jun 07 '18 at 09:43

0 Answers0