locked
MVC Render partial view trough ajax call RRS feed

  • Question

  • I'm new to asp.net mvc and I'm trying to add a partial view in to a div trough ajax call. The problem is that the scripts that I load in the Layout page wont trigger in the partial view. So I'm guessing I have to render that partial view. Can someone point me in the right direction?

    This is the div where I'm trying to add the html result 

            <!-- Tab content 1: End -->
            <div id="caseReference_tab_content" class="tab-content" data-tabid="4">
              
            </div>

    This the ajax call

        $.ajax({
            url: '/Home/LoadTabContent',
            type: 'POST',
            data: { id: buttonValue },
            success: function (result) {
                $("#caseReference_tab_content").html(result);
            }
        });

    This is the ActionResult

            [HttpPost]
            public ActionResult LoadTabContent(string id)
            {
                //Get tab details
                CaseTabDetails caseTabDetails = CaseTabData.GetUserRelatedCasesData(id);
    
                // Get attachments
                List<Attachment> attachments = AttachmentsData.GetAttachmentsData(id);
    
                // Get events
                List<Event> events = EventsData.GetEventsData(id);
    
                // Create object with case details for the new tab.
                CaseDetails caseDetails = new CaseDetails()
                {
                    Title = caseTabDetails.Title,
                    OfficialNumber = caseTabDetails.OfficialNumber,
                    CountryCode = caseTabDetails.CountryCode,
                    CaseType = caseTabDetails.CaseType,
                    Status = caseTabDetails.Status,
                    ImageData = caseTabDetails.ImageData, 
                    ImageDataThumb = caseTabDetails.ImageDataThumb,
                    Attachments = attachments,
                    Events = events
                };
    
                return PartialView("_TabContent", caseDetails);
            }
    

    Monday, July 20, 2020 11:07 AM

All replies

  • Hi there,

    Welcome to MSDN forum.

    Refer to the information you provided, you could try to add the partial view to the views/shared folder.

    If it doesn’t work, we suggest you report it in the ASP.NET forum and start a new thread for more professional support. Thanks for your understanding.

    If you have any other issues about .NET Framework Setup and Servicing in the future, please feel free to post in this forum.

    Have a nice day.

    Sincerely,

    Anna

    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Tuesday, July 21, 2020 3:30 AM