简体   繁体   中英

Modal view (partial) from MVC.Grid

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);
}

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM