[CLOSED] How to Render Ext.NET controls on Bootstrap modal popup using PartialViewResult

Page 1 of 4 123 ... LastLast
  1. #1

    [CLOSED] How to Render Ext.NET controls on Bootstrap modal popup using PartialViewResult

    Hello Team,

    I am unable to render Ext.NET controls on partial view showing on bootstrap popup(modal) when called from following logic. The popup opens ok, but TextField does not get rendered and I see error in developer tools that Failed to load resource: the server responded with a status of 500 (Internal Server Error)

    ContactViewModel.vb
    Imports System.ComponentModel.DataAnnotations
    
    Public Class ContactViewModel
    
        Public Property contact_id As Integer
        Public Property last_name As String
        Public Property first_name As String
        Public Property FullName As String
        Public Property title As String
        Public Property company_name As String
        <EmailAddress(ErrorMessage:="Invalid Email")>
        Public Property email As String
        Public Property phone As String
        Public Property Cellphone As String
        Public Property fax As String
        Public Property address As String
        Public Property city As String
        Public Property state As String
        Public Property zip As String
        Public Property GetContactList As List(Of ContactViewModel)
        Public Property AddContactSearchList As List(Of ContactViewModel)
        Public Property PageFrom As String
        Public Property ContactGridList As List(Of FillContactGridEntity)
    
    End Class

    ContactController.vb

    
    Imports System.Web.Mvc
    Imports System.ComponentModel.DataAnnotations
    
    Namespace Controllers
        Public Class ContactController
            Inherits Controller
            
           
            Function GetContact() As ActionResult
                Dim cViewModel As New ContactViewModel
                cViewModel.ContactList = ContactConsumer.FillContactGrid(String.Empty,0)
                Return View(cViewModel)
            End Function
    
            Function ContactDetail(Optional contactID As Integer = 0) As PartialViewResult
                Dim cViewModel As New ContactViewModel
    			cViewModel.ContactGridList = ContactConsumer.FillContactGrid(contactID)
                Return PartialView("_EditContact", cViewModel)
            End Function
    
        End Class
    End Namespace


    View

    Index.vbhtml
    <div>
    @(Html.X().ResourceManager())
            <!---------Grid Section Start---------->
                    <section Class="grid paddingTop10">
                        <div Class="row">
                            <fieldset>
                                <legend> Contacts Details</legend>
                                <div  id="contactResultDiv">
    
                               
    @(Html.X().GridPanel() _
    .Title("Contacts") _
    .MaxWidth(900) _
    .OverflowX(Overflow.Auto) _
    .OverflowY(Overflow.Auto) _
    .Height(450) _
    .Store(Html.X().Store() _
    .ID("Store2") _
    .PageSize(100) _
    .Model(Html.X().Model() _
    .IDProperty("ID2") _
    .Fields(
    New ModelField("last_name", ModelFieldType.String),
    New ModelField("contact_id", ModelFieldType.Int),
    New ModelField("first_name", ModelFieldType.String),
    New ModelField("title", ModelFieldType.String),
    New ModelField("company_name", ModelFieldType.String),
    New ModelField("email", ModelFieldType.String),
    New ModelField("phone", ModelFieldType.Int),
    New ModelField("Cellphone", ModelFieldType.Int),
    New ModelField("fax", ModelFieldType.Int),
    New ModelField("address", ModelFieldType.String),
    New ModelField("city", ModelFieldType.String),
    New ModelField("state", ModelFieldType.String),
    New ModelField("zip", ModelFieldType.Int)
    )
    ) _
    .DataSource(Model.AddContactSearchList)
    ) _
    .ColumnModel(
    Html.X().Column().Text("Last Name").DataIndex("last_name") _
    ,
    Html.X().Column().Text("First Name").DataIndex("first_name") _
    ,
    Html.X().Column().Text("Title").DataIndex("title") _
    ,
    Html.X().Column().Text("Company").DataIndex("company_name").Width(200) _
    ,
    Html.X().Column().Text("Email").DataIndex("email") _
    ,
    Html.X().Column().Text("Phone").DataIndex("phone") _
    ,
    Html.X().Column().Text("Cell Phone").DataIndex("Cellphone") _
    ,
    Html.X().Column().Text("Fax").DataIndex("fax") _
    ,
    Html.X().Column().Text("Address").DataIndex("address") _
    ,
    Html.X().Column().Text("City").DataIndex("city") _
    ,
    Html.X().Column().Text("State").DataIndex("state") _
    ,
    Html.X().Column().Text("Zip").DataIndex("zip")
    ) _
    .SelectionModel(
    Html.X().RowSelectionModel().Mode(SelectionMode.Multi)
    ) _
    .Listeners(Sub(m) m.RowDblClick.Handler = "OpenContactPopup(record.data.contact_id);"))
                                </div>
                            </fieldset>
                             </div>
                    </section>
    
                    <!---------Grid Section End---------->
    
            </div>
    		
    		
    <div id = "myModal4" Class="modal fade" role="dialog">
    
    </div>
    		
    		
    <script>
    
    function OpenContactPopup(contactID)
        {
            try {
                var pageFrom = $('#PageFrom').val();
    
                $.ajax({
                    type:"POST",
                    url:  '@Url.Action("ContactDetail", "Contact")',
                    dataType: "text",
                    data: JSON.stringify({ contactID: contactID}),
                    contentType: "application/json; charset=utf-8",
                    success: function (data) {
                            $('#myModal4').html(data);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest.textStatus + 'error');
                    }
                });
    
            } catch (e) {
                alert(e.message + 'v');
    
            }
        }
    	
    </script>

    Partial View
    _EditContact.vbhtml

    @modeltype ContactViewModel
    @Using (Html.BeginForm("SaveContacts", "Contact", FormMethod.Post, New With {.Id = "EditContact"}))
    @(Html.X().ResourceManager())
            '<!-- Modal content-->
        @<div class="modal-dialog2" id="id1">
            <div class="modal-content">
                <div class="modal-header">
                    <Button type="button" Class="close" onclick="CancelSave()">&times;</Button>
                    <h4 class="modal-title">@(If(Model.contact_id = 0, "Add contact", "Edit Contact"))</h4>
                </div>
                <div class="modal-body">
                    <section class="free-form paddingTop10">
                        <div class="xopenLink">
    
                            <div class="form-inline width130">
    
                                <div class="form-group">
                                    <label class="labelAlign">Last Name :</label>
                                    @Html.X().TextField().ID("lastNameTxtBox")
                                </div>
                                <div class="form-group">
                                    <label class="labelAlign"for ="first">First Name :</label>
                                    @Html.TextBoxFor(Function(model) model.first_name, New With {.class = "form-control", .maxlength = 20, .id = "first_name_save"})
                                </div>
    
                                <div class="form-group">
                                    <label class="labelAlign">Title :</label>
                                    @Html.TextBoxFor(Function(model) model.title, New With {.class = "form-control", .maxlength = 20, .id = "title_save"})
                                </div>
                                <div class="form-group">
                                    <label class="labelAlign">Company :</label>
                                    @*@Html.TextBoxFor(Function(model) model.company_name, If(Model.company_name IsNot Nothing, Model.company_name, ""), New With {.Class = "form-control"})*@
                                @Html.TextBoxFor(Function(model) model.company_name, New With {.Class = "form-control", .id = "company_name_save"})
                            </div>
                            <div class="form-group">
                                <label class="labelAlign  col-lg-5">Email :</label>
                                <div class="col-lg-7">
                                    @Html.EditorFor(Function(model) model.email, New With {.Class = "form-control", .id = "email_save"})
                                    @Html.ValidationMessageFor(Function(model) model.email)
                                    @*<label><a href="mailto:@Model.email">@Model.email</a></label>*@
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="labelAlign">Phone :</label>
                                @Html.TextBoxFor(Function(model) model.phone, New With {.class = "form-control Decimal", .id = "phone_save"})
                            </div>
                            <div class="form-group">
                                <label class="labelAlign">Fax :</label>
                                @Html.TextBoxFor(Function(model) model.fax, New With {.class = "form-control Decimal", .id = "fax_save"})
                            </div>
                            <div class="form-group">
                                <label class="labelAlign">Cell Phone :</label>
                                @Html.TextBoxFor(Function(model) model.Cellphone, New With {.class = "form-control Decimal", .id = "Cellphone_save"})
                            </div>
                            <div class="form-group">
                                <label class="labelAlign">Address :</label>
                                @Html.TextBoxFor(Function(model) model.address, New With {.class = "form-control", .id = "address_save"})
                            </div>
                            <div class="form-group">
                                <label class="labelAlign">City :</label>
                                @Html.TextBoxFor(Function(model) model.city, New With {.class = "form-control", .id = "city_save"})
                            </div>
                            <div class="form-group">
                                <label class="labelAlign">State :</label>
                                @Html.TextBoxFor(Function(model) model.state, New With {.class = "form-control", .id = "state_save"})
                            </div>
                            <div class="form-group">
                                <label class="labelAlign">Zip :</label>
                                @Html.TextBoxFor(Function(model) model.zip, New With {.class = "form-control Decimal", .id = "zip_save"})
                            </div>
                            @Html.HiddenFor(Function(model) model.contact_id)
                              
                        </div>
    
    
                    </div>
                </section>
                <div Class="modal-footer">
    
                    <div Class="buttonDiv">
                        <div Class="buttonwrapper">
                            <input type="button" id="editBtnSave" Class="btn btn-default" value="@(If(Model.contact_id = 0, "Save", "Update"))" />
                            <button type = "button" Class="btn btn-default"  onclick="CancelSave()" data-dismiss="" data-toggle="modal">Cancel</button>
    
                        </div>
                    </div>
    
                </div>
            </div>
        </div>
           </div>
    End Using
    
    <script>
       
        
        function closepopup() {
    
            $("#id1").modal('hide');
            $("#id1").remove();
        }
      
    
        $('#editBtnSave').on('click', function (event) {
            try {
    
                var a = {};
                a.last_name = $('#last_name_save').val();
                a.first_name = $('#first_name_save').val();
                a.title = $('#title_save').val();
                a.company_name = $('#company_name_save').val();
                a.email = $('#email_save').val();
                a.phone = $('#phone_save').val();
                a.fax = $('#fax_save').val();
                a.Cellphone = $('#Cellphone_save').val();
                a.address = $('#address_save').val();
                a.city = $('#city_save').val();
                a.state = $('#state_save').val();
                a.zip = $('#zip_save').val();
                a.contact_id = $('#contact_id').val();
                $.ajax({
                    type: "POST",
                    url: '@Url.Action("SaveContacts", "Contact")',
                    dataType: "text",
                    data: JSON.stringify({ cViewModel: a }),
                    contentType: "application/json; charset=utf-8",
                    success: function (data) {
                        alert('Data saved')
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest.textStatus + 'error');
                    }
                });
    
    
            } catch (e) {
                //alert(e.message + 'v');
    
            }
        });
    
        function CancelSave() {
            $('#myModal4').modal('hide');
        }
    
    
    </script>
  2. #2
    Setting initScriptMode="Inline" in web.config under tag <extnet> did work the charm for me. Now controls are getting rendered on partial view as well.

    Now the concern is will this change in web.config affect application in other manners?
  3. #3
    Hello!

    Without trying your example, considering your second post, we don't expect using initScriptMode="Inline" should break anything. It is actually the original (and failsafe) approach of Ext.NET, as it injects scripts to the main page instead of creating a script reference to a temporary resource in ext.axd.

    This thread suggests this problem may be a Microsoft limitation regarding sessions' state: [1.5] Error 500 on the major page include when InitScriptMode="linked" in the ResourceManager.. By the time of this thread though, the setting for init script mode was 'inline' by default. It changed since Ext.NET 2 release and we have very very few reports on errors using this approach.

    So while in most situations using InitScriptMode="linked" (current default) works, there are still some situations or project configuration mixups that may trigger this.

    Long story short, you are safe using initScriptMode="inline". Notice: initScriptMode (first lowercase) is used in Web.config and InitScriptMode (first uppercase) used when you pass it as a parameter to Html.X().ResourceManager().

    We'll still give your example a look and see if we can reproduce the issue locally, maybe there's a better approach to it.
    Fabrício Murta
    Developer & Support Expert
  4. #4
    Hi Fabricio,

    Using Inline mode does break things on the popup where we are rendering the controls. In my example, we are rendering GridPanel, and now column width expansion does not work, and sorting does not work as expected and many other javascript errors do come using inline, but when I use Linked mode the control does not even render. Please help!.
  5. #5
    Hello Puneet!

    Sorry for the delay, I'm afraid I don't have good news yet.

    I am just trying to set up your sample code but I see several missing items like the EmailAddress and ContactConsumer entities, to name two.

    In order to reproduce your problem in our end and effectively provide you with feedback (whether that is a bug, a misuse or whatnot) we really need a runnable example like the other time you provided us with.

    You may find it easier to provide a set up project, some people even create the project and commit to a gitHub repository so we can just clone it, open and run. It is up to you to decide whether you provide a fully working sample with full definitions of model view and controller, or a project file.

    Please note we don't want you to provide us with your production code, this would also be just misleading for us as well, the simpler the sample illustrating your issue, the faster we can understand and advise about how to proceed.

    Please take this into consideration if you decide on sharing a project with the test case:
    - never leave your Ext.NET key in the project's Web.config: nobody needs it to run the project from Visual Studio.
    - do not add the Ext.NET DLL files -- specially if you are building Ext.NET yourself from sources
    - let's use VS to our favor: remove/exclude any package directory from solution's packages/ folder, let Visual Studio's NuGet package-restore place the packages back in place on first build (remember to keep packages/repositories.config!).
    - you probably can't upload your project file here -- but you can post a link to your oneDrive, dropbox, github or any other online file sharing mechanism available nowadays so we can get it.

    We hope you understand, and we are looking forward for the runnable sample so we can help you making it work.
    Fabrício Murta
    Developer & Support Expert
  6. #6
    Hey Fabricio,


    I spent some time to create exact example project that I am working and facing issues.

    Here's the project link on dropbox from where you can download.

    EDIT: Removed .zip file

    This above project have package.config file which you can use to identify packages you need to download from Nuget.

    Just to repeat the issue:

    When you click on Edit Button on index display, you will get popup which is going to render Ext.NET gridpanel. Since I have set Inline mode, now it does render but
    1. column does not sort correctly.
    2. column width cannot be changed
    3. There are many errors seen in developer tools console when clicked on column
    4. when popup is closed, nothing on previous screen, where Edit button is placed, works either.



    There is one more thing which I found. If I remove the Ext.NET Button from the display, instead put html input type=button and remove the Html.X().ResourceManager() call from _Layout then everything works normal. That means placement of resources conflicts in case of Inline, because partialView is rendered on same Index page inside <div> and Index page is already associated with Ext.NET resources, and when Partial comes in, it again calls the ResourceManager() and something went wrong.


    I hope you guys will solve this problem.

    Thanks,
    Puneet
    Last edited by geoffrey.mcgill; Jun 15, 2016 at 6:32 PM.
  7. #7
    Hello! Awesome project sample!

    I could see the problem happen... but I'd take a different approach there. Would use more Ext.NET than you are using.

    Basically I'm going to rewrite your example based on this sample: Dynamic Partial Rendering - Window

    But as I am not very keen on VB.NET I might take a little more time to readapt your sample to the approach used here.

    Have you reviewed the above example before? Basically, instead of defining your modal on a plain div and jQuerying the partial view, use Ext.NET and a direct Event (bound to the button click) to show the window, and voila!

    BUT, as the window in the example is very simple, it is possible that something else breaks in the process for your test case, so we have to get it working before we can say it works or not.

    What would be left in the example is just passing the parameter to the directEvent. This is done via (in general lines, C#):

    Html.X().Button().DirectEvents(de => {
        de.Click.Url("Edit", "Home") @* actually, if it is in the same controller you won't need the ", "Home""  part *@
        de.Click.ExtraParams.Add(new Ext.Net.Parameter("companyId", "2", ParameterMode.Raw));
    })
    And, well, this should just do. We'll see. An MVC example (in C#) using these direct event parameters is Dynamic Partial Rendering - Add Tab.

    I am sure that, following the approach on these examples, the page will work. Sorry for not providing the full feedback yet, but these bits may help you progress more on your page and I felt like sharing already!

    Hope this helps!

    EDIT: By the way, for starters, this new approach might just work with any InitScriptMode setting. I'll start by the default (linked), and when it works, switch to inline and see what happens.
  8. #8
    Using more Ext.NET is another option which require us to give more time, since we are already in the last sprint of our project and using full ext.NET will require us to input more time into project which is quite impossible right now. Our main idea is to add full featured controls of Ext.NET rather than full framework, so if you could help us render controls using our approach that will be great!!

    On another note, the example you gave me to use, will work fine where i have to pass only bunch of parameters, but what about the cases where Action is expecting full model to be passed?
  9. #9
    Hello Puneet!

    On another note, the example you gave me to use, will work fine where i have to pass only bunch of parameters, but what about the cases where Action is expecting full model to be passed?
    Should work just as same, although slower if the full model means more data through the client-to-server communication!
    Fabrício Murta
    Developer & Support Expert
  10. #10
    Hello!

    Personally, I would highly recommend to switch to the approach suggested by Fabricio as soon as possible.

    Using more Ext.NET is another option which require us to give more time, since we are already in the last sprint of our project and using full ext.NET will require us to input more time into project which is quite impossible right now.
    Yes, that is understandable and I'll try to help with this:

    if you could help us render controls using our approach that will be great
    In general, rendering Ext.NET Partial Views in such a manner is not supported, but I had some ideas to try and seems I was able to get your demo project working. I am not sure it is going to work in all scenarios, but if you are really running out of time, you could try.

    To get your demo project working, please do the following:

    1. Add this to _Layout.vbhtml. It prevents Ext.net.ResourceMgr.init to be executed twice.

    <head>
        ... all the existing <head>'s stuff ...
    
        <script>
            Ext.net.ResourceMgr.init = Ext.Function.createInterceptor(Ext.net.ResourceMgr.init, function () {
                if (this.initialized) {
                    console.log("return false");
                    return false; // prevents execution of original Ext.net.ResourceMgr.init
                }
    
                this.initialized = true;
            });
        </script>
    </head>
    2. Set up this ResourceManager in _CompanyDetail.vbhtml (but keep the position of the ResourceManager in the partial view). It ensures Ext.NET JavaScript and CSS resources and not loaded since they are already loaded with the main view.
    @Html.X().ResourceManager().RenderScripts(False).RenderStyles(False)
    3. In _CompanyDetail.vbhtml add this thing right at the top of ResourceManager. It helps with the scripts execution sequence.
    @Html.X().ResourcePlaceHolder().Mode(ResourceMode.Script)
    4. Set up ID for the top Panel. It helps with destroying Ext.NET components. If no unique ID then a new Panel component will be created each time you click the Edit button which can result in a memory leak. You should either care by your own about destroying Ext.NET components (component.destroy() call; just erasing HTML is not enough) or you can set up IDs for all top level Ext.NET components and they will be destroyed automatically if a component with the same ID is rendered.
    Html.X().Panel.ID("Panel1")
    5. Running $('#myModal2').html(data); before $('#myModal2').show(); results in a broken layout - zero Panel's height. You can either do
    success: function (data) {
        $('#myModal2').show();
        $('#myModal2').html(data);
        $("#myModal2").addClass("in");
    }
    or

    success: function (data) {
        $('#myModal2').html(data);
        $('#myModal2').show();
        $("#myModal2").addClass("in");
        App.Panel1.updateLayout();
    }
    These steps are only required if a partial view is rendered in the way as you do it and to the parent view where Ext.NET is already presented.

    And again, this helped with your demo project, but please know it is quite hacky and I cannot guarantee it is going to work in all the scenarios. I can be only used as an attempt to get it working in the lack of time condition. Eventually, it should be changed to another approach.
Page 1 of 4 123 ... LastLast

Similar Threads

  1. Replies: 3
    Last Post: May 25, 2016, 4:22 PM
  2. [CLOSED] Error in Namespace when PartialViewResult render.
    By softmachine2011 in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Sep 28, 2012, 2:10 PM
  3. Replies: 1
    Last Post: Aug 10, 2012, 1:09 PM
  4. [CLOSED] Open a modal popup from a modal popup
    By Aparna_B in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 24, 2012, 8:58 AM
  5. [CLOSED] PartialViewResult Controls in MVC 2
    By tiramisu in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Apr 26, 2010, 9:05 AM

Tags for this Thread

Posting Permissions