简体   繁体   English

向div附加部分视图内容

[英]appending div with partial view content

I'm sending request from my view to the controller which as a result sending partialview page. 我正在将请求从我的视图发送到控制器,从而发送了partialview页面。 Result is appended in desired div. 结果将添加到所需的div中。 Only problem is that partial view content is displayed as source html content (css is not rendered properly). 唯一的问题是部分视图内容显示为源html内容(css不能正确呈现)。

Since I'm guessing that problem may be inside javascript or partialview view here it is 由于我猜测这个问题可能在javascript或partialview视图内,因此

partiaView.cshtml partiaView.cshtml

@foreach (var item in Model)
{
    <div class="product clearfix">
        <div class="l-new">
            <a href="#">
                <!-- -->
            </a>
        </div>
    ...
    </div>
}

jsfile.js jsfile.js

function GetTabData(xdata) {
    $.ajax({
        url: ('/Home/GetData'),
        type: 'POST',
        contentType: 'application/json',
        data: JSON.stringify({ id: xdata }),

        success: function (result) {
            $.each(result, function (i, item) {               
                $("#mytabDiv").append(item);                
            })
        },
        error: function () { alert("error"); }
    });
}

Thanks 谢谢

Update: When I'm using 更新:当我使用

> html

instead of append 而不是append

$("#mytabDiv").html(item);        

div content is not populated at all. div内容根本没有填充。

Since your partial expecting IEnumerable collection you don't need to iterate on js side. 由于您的部分期望IEnumerable集合,因此您无需在js端进行迭代。 Just send result. 只是发送结果。

These should work 这些应该工作

success: function (result) {
           $("#mytabDiv").html(result);                
         },
         error: function () { alert("error"); }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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