在javascript bootgrid中调用Controller的动作

时间:2015-02-05 17:11:31

标签: javascript ajax asp.net-mvc-4

我想在控制器的局部视图中调用一个我自己的Modal of bootstrap,我使用JQuery-Ajax和Bootgrid的JavaScript

enter code here var grid = $("#grid").bootgrid(
{
    ajax: true,
    url: "/Currency/listCurrencyJson",
    formatters: {
    "commands": function(column, row)
    {
        return "<button type=\"button\" class=\"btn btn-default btn-lg delete\" data-row-id=\"" + row.id + "\"><span class=\"glyphicon glyphicon-star\" aria-hidden=\"true\"></span> Star</button>" +
        "<button type=\"button\" class=\"btn btn-xs btn-default command-edit\" data-row-id=\"" + row.id + "\"><span class=\"fa fa-pencil\"></span></button> " +
            "<button type=\"button\" class=\"btn btn-xs btn-default command-delete\" data-row-id=\"" + row.id + "\"><span class=\"fa fa-trash-o\"></span></button>";
    }
}
}).on("loaded.rs.jquery.bootgrid", function () 
{
    /* Executes after data is loaded and rendered */
     grid.find(".command-edit").on("click", function (e) {
    alert("You pressed edit on row: " + $(this).data("row-id"));
}).end().find(".delete").on("click", function deleteCurrency(id)
{
    $.ajax(
    {
       url: '/Currency/createCurrency',
       type: "POST",
       data: { "row-id": "row-id" },
       success: function()
       {
            //alert("Done");  
       }
 });
 });
});

1 个答案:

答案 0 :(得分:0)

ActionLink创建的链接不是按钮。相反,你可以用链接替换你的按钮,并使用CSS来设置它们看起来像按钮。

然后,您只需创建html链接,而无需使用C#ActionLink方法。输出结果将是相同的:

<a href="/Currency/Delete" class="button-link-class">Read More<span class="arrow">→</span></a>

CSS:

.button-link-class
{
     font: bold 11px Arial;
     text-decoration: none;
     background-color: #EEEEEE;
     color: #333333;
     padding: 2px 6px 2px 6px;
     border-top: 1px solid #CCCCCC;
     border-right: 1px solid #333333;
     border-bottom: 1px solid #333333;
     border-left: 1px solid #CCCCCC;
}