0

I am trying to use jQuery ajax with MVC I can get it to post back to the action I want and it returns the ViewData objects with updated Data but never renders the HTML. I have a View which contains some MVC User Controls and I want them to update on a timer.

Here is my View Markup

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/PageWithSummaryViewAndTabs.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="FullCaseTitle" ContentPlaceHolderID="TitleContent" runat="server">

</asp:Content>

<asp:Content ID="FullCaseContent" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
window.setInterval(test, 5000);
function test() {
    jQuery.get("/PatientCase/RefreshEPRF", function(response) { });
}
</script>

<div id="loadingDiv" style="display:none">Updating</div>

   <input id="refreshPatientCaseIndexButton" type="submit" visible="true" title="refresh" value="Refresh" />
    <h2>Full Case</h2>
    <div id="EPRFContent"> 
        <%Html.RenderPartial(@"~/Views/PatientCase/SectionEPRF.ascx"); %>
        <%Html.RenderPartial(@"~/Views/PatientCase/SectionDrugs.ascx"); %>
    </div>
    <div id="ImageContent"> 
        <%Html.RenderPartial(@"~/Views/PatientCase/SectionImagery.ascx"); %>
    </div>
</asp:Content>

On postback i call a Action Called RefreshEPRF which loads just the required user controls again

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%Html.RenderPartial(@"~/Views/PatientCase/SectionEPRF.ascx"); %>
<%Html.RenderPartial(@"~/Views/PatientCase/SectionDrugs.ascx"); %>

And finaly the marpup in the control

<table id="detailstable">
    <tr><td id="detailslablecolumn">Patient Name : </td><td>
    <%
    foreach (var item in (List<STS_Lite.Models.PatinetCase.EPRFItem>)ViewData["EPRF"])
    {
        if (item.datumItemId == 46)
        {
            if (item.Stroke)
            {
            %>
                <img src="/PatientCaseIndex/InkImageData/GetInkImage/<%=ViewData["PatientCaseId"]%>/<%=ViewData["TemplateInstanceId"]%>/<%=item.TemplateItemId %>" />
            <%
            }
            else
            {%>
                <%=item.Value.ToString()%>
            <%} 
            break;
        }
    } 
%></td></tr><table>

When I step through this code the ViewData in the user control has the new updated values but the page comes back with no new values. I have tried the jQuery.get and ajax but with no luck. Any help would be great thanks

1 Answer 1

1

You have to write your response... try doing this :

    jQuery.get("/PatientCase/RefreshEPRF", function(response) { 
        $("#EPRFContent").html(response) }); 

The response parameter should contain your view, and doing this simply put its content into your div.

your action Called RefreshEPRF should however return a partial view

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.