views:

370

answers:

1

Hi, Im trying to use jqeury 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 i 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"); %>

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"&gt;
<%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

A: 

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

moi_meme
That done the trick, Thank you :)
Troublesum