使用buttonclick MVC上的Ajax.ActionLink / AJAX-post将partialview发布到div

时间:2014-03-07 08:11:06

标签: jquery ajax asp.net-mvc partial-views

我的Ajax.ActionLink出现问题,点击我的按钮时得到HTTP ERROR 400 - 错误请求的答案。我尝试了两种方法,但它们都不适合我。我不确定这是不是问题,但是当我试图填充它时,div(calcInput)不是空的。

为这项工作提供一些帮助会很棒。

首次尝试:

我的HTML:

<button type="button" class="btn btn-default btn-lg" id="btnCreateAmort"
                    onclick="location.href='@Ajax.ActionLink("Amortization", "Calculation", new AjaxOptions
                    {
                        UpdateTargetId = "calcInput",
                        InsertionMode = InsertionMode.Replace
                    })'" title="Calculate amortization calculation">Amortization</button>
<div class="calcInput" id="calcInput">//This is where Amortization should be posted</div>

我的CalculationController:

    [HttpPost]
    public ActionResult Amortization()
    {
        return PartialView("Amortization");
    }

第二次尝试(与上面相同的HTML):

我也尝试过使用Ajax帖子,但后来我认为上面的代码会更容易(尽管我想了解更多有关AJAX调用的内容)。

$(document).on('click', '#btnCreateAmort', function () {
$.ajax
    ({
        url: 'Calculation/Amortization',
        type: 'POST',
        dataType: 'json',
        contentType: 'application/json',
        success: function (data) {
            $("#calcInput").html(data);
        }
    });

});

当我尝试这种方式时,我什么都没发生,但是该方法被执行(尝试在开头放置一个警告框)。

0 个答案:

没有答案
相关问题