0

I'm sending request from my view to the controller which as a result sending partialview page. Result is appended in desired div. Only problem is that partial view content is displayed as source html content (css is not rendered properly).

Since I'm guessing that problem may be inside javascript or partialview view here it is

partiaView.cshtml

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

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

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

div content is not populated at all.

6
  • I dont see any div with id as mytabDiv Commented Dec 27, 2012 at 12:46
  • that div is on the index.cshtml, from that page request is send to js. No need to paste that here. Commented Dec 27, 2012 at 12:49
  • did you refer the css file ? Commented Dec 27, 2012 at 13:01
  • yep, just tried with $("#mytabDiv").html(item); without luck. Now result div is empty. Commented Dec 27, 2012 at 13:08
  • What does /Home/GetData return? Commented Dec 27, 2012 at 13:13

1 Answer 1

1

Since your partial expecting IEnumerable collection you don't need to iterate on js side. Just send result.

These should work

success: function (result) {
           $("#mytabDiv").html(result);                
         },
         error: function () { alert("error"); }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.