2

I have a cshtml page (index) that displays a Grid.MVC with rows of data. When the user clicks on the ID row I need to display a popup window that provides more detail information. I have a break point in my JavaScript code but it is never hit. Right now the code calls the controller instead of the function.

cshtml code:

<div class="container-fluid">
    @Html.Grid(Model).Columns(columns =>
{
    columns.Add(c => c.task_id).Encoded(false).Titled("ID").Sanitized(false).Sortable(true).RenderValueAs(c => @Html.ActionLink(c.task_id.ToString(), "viewTransfers", new { taskId=c.task_id }, new { @onclick = "getTransfers('" + c.task_id + "')"}));
    columns.Add(c => c.company).Titled("Company");
})Filterable(false).WithPaging(int.Parse(EPH.Common.Util.GetConfigSetting("PageSize"))).Selectable(true)

</div>

<script type="text/javascript">
    $(function() {
        $('#getTransfers').click(function (e) {
            e.preventDefault();
            $(this).modal();
        });
    });
</script>

Controller:

public ActionResult ViewTransfers(int taskId)
{
    var myQuery = from transfers in db.fals_ftp_watcher_transfers
        where transfers.task_id == taskId
        orderby transfers.imp_date ascending
        select transfers;
    return View(myQuery);
}
Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61
Craig
  • 1,205
  • 2
  • 21
  • 54

1 Answers1

1

There are a couple of things you need to change here.

Your JavaScript is looking for a dom element with the id of getTransfers and one doesn't exist.

I would change it so that the links you are generating have a class of getTransfers instead.

Your action link would become:

@Html.ActionLink(c.task_id.ToString(), 
    "viewTransfers", "controllerName", 
    new { taskId = c.task_id }, 
    new { @class = "getTransfers" })

Please note you will need to change "controllerName" to your controller name.

Your JavaScript would become:

<script type="text/javascript">
    $(function() {
        $('.getTransfers').click(function (e) {
            e.preventDefault();
            $(this).modal();
        });
    });
</script>
hutchonoid
  • 32,982
  • 15
  • 99
  • 104