簡體   English   中英

html不在局部視圖中呈現

[英]html doesnt render in partial view

以下是我用來呈現html視圖的代碼。 @ {Layout = null; }

<script type="text/javascript">
    $(document).ready(function () {
        debugger;
        $("#divChart").load('http://localhost/abcd.Portal/BarChart.html');
    });
</script>


<div style="width: 100%;" id="divChart"></div>

我正在嘗試加載的HTML

<style>
    .bar {
        fill: steelblue;
    }

        .bar:hover {
            fill: brown;
        }

    .axis {
        font: 10px sans-serif;
    }

        .axis path,
        .axis line {
            fill: none;
            stroke: #000;
            shape-rendering: crispEdges;
        }

    .x.axis path {
        display: none;
    }
</style>
<body>

    <script>
        debugger;
        var margin = { top: 20, right: 20, bottom: 30, left: 40 },
            width = 960 - margin.left - margin.right,
            height = 500 - margin.top - margin.bottom;

        var x = d3.scale.ordinal()
            .rangeRoundBands([0, width], .1);

        var y = d3.scale.linear()
            .range([height, 0]);

        var xAxis = d3.svg.axis()
            .scale(x)
            .orient("bottom");

        var yAxis = d3.svg.axis()
            .scale(y)
            .orient("left")
            .ticks(10, "%");

        var svg = d3.select("body").append("svg")
            .attr("width", width + margin.left + margin.right)
            .attr("height", height + margin.top + margin.bottom)
          .append("g")
            .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

        $.ajax({
            url: 'http://localhost/abcd.Portal/Dashboard/GetData',
            type: 'GET',
            data: '',
            cache: false,
            dataType: 'text',
            async: true,
            error: function (xhr) {
                //alert('Error: ' + xhr.statusText);
            },
            success: function (result) {
                debugger;
                result = eval(JSON.parse(result));

                x.domain(result.map(function (d) { return d.letter; }));
                y.domain([0, d3.max(result, function (d) { return d.frequency; })]);

                svg.append("g")
                    .attr("class", "x axis")
                    .attr("transform", "translate(0," + height + ")")
                    .call(xAxis);

                svg.append("g")
                    .attr("class", "y axis")
                    .call(yAxis)
                  .append("text")
                    .attr("transform", "rotate(-90)")
                    .attr("y", 6)
                    .attr("dy", ".71em")
                    .style("text-anchor", "end")
                    .text("Frequency");

                svg.selectAll(".bar")
                    .data(result)
                  .enter().append("rect")
                    .attr("class", "bar")
                    .attr("x", function (d) { return x(d.letter); })
                    .attr("width", x.rangeBand())
                    .attr("y", function (d) { return y(d.frequency); })
                    .attr("height", function (d) { return height - y(d.frequency); });
            }
        });

        function type(d) {
            d.frequency = +d.frequency;
            return d;
        }

    </script>
</body>

我沒有收到任何錯誤,但是我的視圖沒有渲染。 我正在嘗試繪制d3條形圖。 任何建議,我要去哪里錯了。

我有一個加載我的部分視圖的父母。 現在,如果我在局部視圖中編寫html代碼,則會顯示錯誤。 因此,我嘗試加載html文件。

這不是使用jquery加載部分視圖的方法,請對其執行操作。

創建一個將返回部分視圖的操作:

public ActionResult BarChart()
{
  return View();
}

並在jquery中:

$(document).ready(function () {
        debugger;
        $("#divChart").load('@Url.Action("BarChart","ControllerName")');
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM