How to call partial function after added via append

2

Hello, I have a partial view , which I render with the following code:

        $.ajax({
            url: URL,
            success: function (data) {
                $("#DIV").append(data);
            }
        });

And within that page, I call a function

<script> 
   Funcao(selectorId);
</script>

I need this function to be called within partial view, after being loaded with append

Since the parameter (selectorId) of the function is received unique, then every time I call to rename in $("#DIV").append(data); the selectorId will be different ...

How can I do this?

My element is mounted like this in ASP.NET code:

<input id="Contatos[@Guid.NewGuid().ToString()].Nome" name="Contatos[@Guid.NewGuid().ToString()].Nome" type="text" value="0">

Example of resulting ID:

Contatos[8902dbfd-e856-48c6-8f17-d0548b2dea62].Nome
    
asked by anonymous 26.01.2015 / 21:23

2 answers

2

This type of ID has several characters that are not interpreted literally when used in a selector. For example, a selector like this:

#Contatos[8902dbfd-e856-48c6-8f17-d0548b2dea62].Nome

It will look for an element whose ID is Contatos , which has an attribute called 8902dbfd-e856-48c6-8f17-d0548b2dea62 and that has the Nome class. For example:

<div id="Contatos" class="Nome" 8902dbfd-e856-48c6-8f17-d0548b2dea62></div>

But that's not what you want ... So you need to escape the characters that are causing confusion, [ , ] and . . JQuery needs to get this:

#Contatos\[8902dbfd-e856-48c6-8f17-d0548b2dea62\]\.Nome

So the string needs to be set like this:

"#Contatos\[8902dbfd-e856-48c6-8f17-d0548b2dea62\]\.Nome"

Reference : How to use a bracket name (brackets) in a jQuery selector?

    
27.01.2015 / 15:56
1

Create the function in partial without calling it and call after append.

        $.ajax({
        url: URL,
        success: function (data) {
            $("#DIV").append(data);
            funcaoDentroDaPartial();
        }
    
27.01.2015 / 00:23