2
Hi, I have a partial view
, that I surrender 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 inside the partial view,
after being loaded with append
Because the parameter (selectorId) of the function is received only, so every time I call to render in $("#DIV").append(data);
the selectorId parameter will be different...
How can I do that?
My element is mounted like this in the 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
If I understand correctly, what you have should work. There is some error in the console?
– bfavaretto
not @bfavaretto , however, it seems to me that the element when I call my function, has not yet been rendered, as it does not find some date attributes...
– Rod
When you say "within that page" refers to partial? The script is at the end of partial?
– bfavaretto
Yes, it should be called after the append, but the script is inside the partial, is that I Gero the attribute "ID" that is passed to the function, internally in Partial, so each time I make a call of this partial the attribute Id will be a different...
– Rod
You cannot return this value in the ajax call and run the function there with this ID?
– André Ribeiro
@bfavaretto seeing his answers, saw that works or worked with c#, well, the idea, is that I feed my elements the elements like this:
<input id="Contatos[@Guid.NewGuid().ToString()].Nome" name="Contatos[@Guid.NewGuid().ToString()].Nome" type="text" value="0">
Then I call the function by passing the parameter Id, and there in the function use $("#" + parameter") to pick up the element– Rod
@Andréribeiro can not say, since I Gero the attribute Id there in the partial view, as I showed in the comment above
– Rod
@Rod I think your JS code is ok. The problem may be that your selector contains a
.
, that jQ will interpret as class selector. Try to escape the point with\.
in office.– bfavaretto
@bfavaretto can be...my Id is being generated like this:
Contatos[8902dbfd-e856-48c6-8f17-d0548b2dea62].Nome
But as it goes on:Contatos[8902dbfd-e856-48c6-8f17-d0548b2dea62]\\.Nome
I was also unsuccessful– Rod
Brackets can also be problem, have another sense in selectors.
– bfavaretto
@bfavaretto exactly :D worked...if you want to provide an answer, I add too much detail to the question
– Rod
I will try to post later if no one does this before :) I take this opportunity to record the link of a related question: http://answall.com/questions/211/como-usar-um-nome-com-colchete-par%C3%Aanteses-retos-num-selector-de-jquery
– bfavaretto