MVC Partial View

Topics: MVC
Jul 3, 2011 at 8:52 PM

I have created a new MVC 3 razor application and modified the about.cshtml  to include code

 <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.unobtrusive-ajax.js"></script>

<div id="divInsert" />

<p>
     <a id="aShowInsert">dialog register</a>
</p>


<script type="text/javascript">
    var dialog;
    $(document).ready(function () {
        //alert('net');
        $("#aShowInsert").click(function () {
            $("#divInsert").empty();
            $("#divInsert").load("Home/parialContent", function () {
                alert('dialog content');
                $("#inputCloseModal").click(function () {
                    dialog.dialog('close');
                    return false;
                });
            });

            dialog.dialog("open");
            return false;
        });
        dialog = $("#divInsert").dialog({
            title: "Insert",
            resizable: false,
            modal: true,
            autoOpen: false
        });
    });
 </script>

In the HomeController.cs i added the code

        public ActionResult parialContent()
        {
            return PartialView("/Views/Home/Content.cshtml");
        }

Create a new view "Content.cshtml" with some text.

This application run in the external CMS project and show a dialog with text but when i try to implement somehting like this in Composite CMS the code does not show the dialog.

Debugging shows that the code does read the partial view Content.cshtml.

If someone has experience with Partial Views in C1 CMS system i would greatly appreciate the insight to make this work.

Thanks in advance.

Developer
Jul 4, 2011 at 9:06 AM
Edited Jul 4, 2011 at 9:07 AM

Hi, Can you add some parameter to parialContent() ?

public ActionResult parialContent(string str)
        {
            return PartialView("/Views/Home/Content.cshtml");
        }

  $("#divInsert").load("Home/parialContent", {string:"test"},function () {

 

Problem can be that "load" send GET request instead POST (GET Ajax request can have problems in combination IIS + MVC + C1)

Jul 4, 2011 at 5:15 PM

Awsome.

Thanks for the help again.

Minh