@Vie" />

MVC Partial View Returns Whole Page Instead of Just the Partial

1372 观看


852 作者的声誉

I have the following partial view named "_transactions":

<div id="section-transactions" class="documentsanchor">
    <div class="row">
        <div class="col-lg-12">
                <h4 class="company-headings">@ViewBag.SecSymbol Transactions</h4>

I render it using

 @{Html.RenderAction("Transactions", "Company");}

and this is the Transactions method from the Company controller:

    public async Task<PartialViewResult> Transactions()
        ViewBag.SecSymbol = "test";

        return PartialView("_transactions");

It's on a page with other partial views.

This works fine. However, I have a button on the page that should get a new partial view and replace the current one. It makes an ajax call as follows

    $("#btn_transactions").click(function (e) {           
        var url = "Company/Transactions";
            url: url,
            success: function (result) {
            error: function () {
                alert("Error occured");

The issue is that the whole page is returned in "result", that is, all partials as well as the layout, when all I want is the transactions partial. What am I doing wrong?

作者: Scott 的来源 发布者: 2017 年 12 月 27 日

回应 (1)


44 作者的声誉

Add this code in partial view

作者: Uttam Suthar 发布者: 29.12.2017 01:16