Attempting to update partial view using Ajax.ActionLink gives error in MicrosoftAjax.js
        Posted  
        
            by mwright
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by mwright
        
        
        
        Published on 2010-04-07T22:01:25Z
        Indexed on 
            2010/04/08
            17:23 UTC
        
        
        Read the original article
        Hit count: 1072
        
asp.net-mvc
|partial-views
I am trying to update the partial view ( "OnlyPartialView" ) from an Ajax.ActionLink which is in the same partial view. While executing the foreach loop it throws this error in a popup box in visual studio:
htmlfile: Unknown runtime error
This error puts the break point in the MicrosoftAjax.js file, Line 5, Col 83,632, Ch 83632. The page is not updated appropriately.
Any thoughts or ideas on how I could troubleshoot this? It was previously nested partial views, I've simplified it for this example but this code produces the same error.
Is there a better way to do what I am trying to do?
Index Page:
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<ul>
    <% foreach (DomainObject domainObject in Model) { %>
        <% Html.RenderPartial("OnlyPartialView", domainObject); %>
    <% } %>
</ul>
OnlyPartialView:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ProjectName.Models.DomainObject>" %>
<%@ Import Namespace="ProjectName.Models"%>
<li>
    <div id="<%=Model.Id%>">
        //DISPLAY ATTRIBUTES
    </div>
    <div id="<%= Model.Id %>ActionStateLinks">
         <% foreach ( var actionStateLink in Model.States[0].State.ActionStateLinks)
         {%>
             <div id="Div1">
                 <div>
                     <%= actionStateLink.Action.Name %>
                 </div>
                 <div>
                     <%= Ajax.ActionLink("Submit this Action",
                         "DoAction",
                         "ViewController",
                         new { id = Model.Id, id2 = actionStateLink.ActionStateLinkId },
                         new AjaxOptions{ UpdateTargetId = Model.Id.ToString()} )%>
                  </div>
            </div>
            <br />
        <%} %>  
    </div>
</li>
Controller:
public ActionResult DoAction(Guid id, Guid id2)
{
    DomainObject domainObject = _repository.GetDomainObject(id);
    ActionStateLink actionStateLink = _repository.GetActionStateLink(id2);
    domainObject.States[0].StateId = actionStateLink.FollowingStateId;
    repository.AddDomainObjectAction(domainObject, actionStateLink, DateTime.Now);
    _repository.Save();
    return PartialView("OnlyPartialView", _repository.GetDomainObject(id));
}
© Stack Overflow or respective owner