We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

PartialView

VS 2013
Syncfusion MVC: 12.1451.0.49

I View where I do this:

foreach (var lve in Model.Layouts)
{
  <div id="layout_@(ii.ToString())">
  @{
    Html.RenderPartial("Layouts_Grid", (Models.LayoutEntry)lve, new ViewDataDictionary { { "id", ii }, { "data", Model.ExampleData } });
    ii++;
  }
  </div>
}

I have an action to repopulate the div after a cancel or save event. Inside View Layouts_Grid are some ejButtons and an ejGrid and in the save or cancel events I'm simply calling the action to get the html for the partial view. Looking at the return content all looks good, the problem is the ejButtons and the ejGrid don't "redraw" correctly so in my ajax success function I tried gridObj.templateRefresh but get the following error:

Error: ejGrid: methods/properties can be accessed only after plugin creation...

Here is what the ajax success function looks like for reference:

...
success: function (response)
{
$(divID).html(response);
var gridObj = $("#layoutGrid_" + index).ejGrid("instance");
gridObj.templateRefresh();
},
...

any ideas?

Thanks,

Rick

6 Replies

HU Huntero July 3, 2014 10:34 AM UTC

Sounds like a similar problem i had few days ago that i posted here: https://www.syncfusion.com/support/forums/aspnetmvc/grid/116890 

    Try adding the ej.widget.init with the id of the container your updating.

success: function (response)
{
$(divID).html(response);
                                
                                ej.widget.init($("#AjaxUpdateTarget-container"));
}

If that doesn't fix it just wait a bit for an official response :)


RT Rick Thompson July 3, 2014 01:35 PM UTC

Hello Huntero,

I tried what you recommended and it didn't work, as you indicated it may not.

However, if I add

@Html.EJ().ScriptManager()

to the bottom of my partial view (which also exists in _Layouts.cshtml) everything worked. Not sure if there will be any repercussions but for now it looks good.

Thanks,

Rick 


RT Rick Thompson July 3, 2014 01:38 PM UTC

One more thing, I didn't have to do anything special in my ajax success function, this is all I had:

...
success: function (response)
{
  $(divID).html(response);
},
...

All my ej controls rendered correctly simply by having the @Html.EJ().ScriptManager() in my partial view, and there seem to be no "clash" with it also being in _Layouts.cshtml.


RU Ragavee U S Syncfusion Team July 3, 2014 02:41 PM UTC

Hi Rick

 

We have analyzed the issue that you have mentioned. For your convenience, we have created a simple sample with partial view to repopulate the data within the div using the ajax call. The sample can be downloaded from the attachment. Please refer the below code snippet:

 

[In index.cshtml]

<div id="main">

@Html.EJ().Button("click").Text("Render Grid").Render()

@Html.Partial("_partial", this.ViewData)

    </div>

 

<script type="text/javascript">

    $("#click").click(function () {       

        $.ajax

                ({

                    url: "Home/Productpartial",

                    type: 'GET',

                    success: function (data) {                       

                        $("#main").html(data);                       

                    }

                });

    });

</script>

 

[In controller]

        public ActionResult Productpartial()

        {

            var DataSource = new NorthwindDataContext().EmployeeViews.ToList();

            ViewData["datasource"] = DataSource;

            return PartialView("_partial",ViewData);

        }

 

We suggest you to use return PartialView("_partial",ViewData) instead of return View("_partial",ViewData), because the whole html page is bound to the data of the success event of ajax call and the scripts tags are again included within the partial page content. Hence this issue had arosed.

 

Note: While rendering a control in the partial view, we need to specify @Html.EJ().ScriptManager() in the partial view page after the initializing the control. Please refer the below code snippet.

 

[In _partial.cshtml]

@(Html.EJ().Grid< object >("Grid")

        .Datasource((IEnumerable<object>)ViewData["datasource"])

        .AllowSorting()

        .AllowPaging()

        .Render())

@Html.EJ().ScriptManager()

 

Please let us know if you need any further assistance.

 

Regards

Ragavee U S



Attachment: SampleApp_6d67b283.zip


RT Rick Thompson July 3, 2014 03:17 PM UTC

Thanks for the information. I was doing everything as indicated, but I didn't have the @Html.EJ().ScriptManager(). As indicated in one of my earlier replies I added @Html.EJ().ScriptManager() and it began working.

Thanks,

Rick


RU Ragavee U S Syncfusion Team July 4, 2014 07:22 AM UTC

Hi Rick

 

Thanks for the update.

 

We are happy that your issue is resolved.

 

If you have any issues in the future, please get back to us. We will be happy to assist you.

 

Please let us know if you would require any further assistance.

 

Regards

Ragavee U S


Loader.
Up arrow icon