views:

459

answers:

1

Hi

I have a index page the renders objects from my database as a treeview, each item has a link href="/MessageGroupType/Edit/1002 that makes an Ajax call to display a partial view in a DIV.

Within the partial view there is a delete button which calls my controller to delete the item.

However, i do a check to make sure the item can be deleted, if the item cant be deleted then i wish a pop-up to appear back on the edit form telling the user they cant delete this record.

In my Edit partial view i have the following code

<asp:PlaceHolder runat="server">
        <script src="<%= Url.Content("../../Scripts/JQuery/jquery-1.4.1.min.js") %>" type="text/javascript">
        </script>
</asp:PlaceHolder>


<script type="text/javascript" >
     $(function() {
         $("#dialog").dialog();
     });

</script>

  <% if (Boolean.Parse(ViewData["DisplayWindow"].ToString())){%>
     <div id="dialog" title="Cannot Delete Message Group Type">
             <p>This Mesage group Type Cannot be deleted as is linked to other message group Types </p>
             </div>
     <% }%>

So my main questions are

  1. Can i make a reference to a javascript script within my Partial View (i dont want my master page to be called on the partial view)
  2. When i dynamically load the partial view data into my DIV - can i then after calling my controller insert another DIV into the first DIV.
  3. I am i doing this the wrong way - so any pointers is appreciated

Cheers

+1  A: 

In your tree view, you can add an Ajax.ActionLink with a OnFailure option in AjaxOptions that will point to your $("#dialog").dialog();

In your controller, if the user can not delete the record associate a bad request code (Response.StatusCode = (int)HttpStatusCode.BadRequest;) to your HttpResponse, so your OnFailure function will be called (and your popup displayed).

Do not forget to associate a OnSuccess function to your Ajax.ActionLink if the record has been deleted

Gregoire
Hi - Sorry I should have pointed this out - i have some similar already in place i havea ajax action link with a Confirm = "Are you sure you want to delete display. On Selecting yes my controller is called - and it is at this point i would like the delete to go into my controller - will the Onfailure trigger the function i require even thopugh the Ok button has been pressed,Thnaks for your input much appreicated.
Gavin campbell