DropDownItem doesn't load items after update(Javascript) partial view












0















I have the following functionality: A user registers a series of data in a form, after sending the form and saving it in the database, it is redirected to a second form, where it must load the rest of the information, it is possible that in this second form, contains a lot of values of the first form, but this is not always the case, that is why in this second form there is a button that allows "copy" the data of the first form, to reduce data entry.



As I did?



I created a main view, where the form is loaded as a partial view with the empty model fields, so that the user can enter the information if it is not the same as the first form
Main View:



    <div id="partialView">
@Html.Partial("_CreatePartialResponsable", Model)
</div>


In the form that contains the partial view, there is a dropdowlist that is filled through a web service. This dropdow is filled correctly when loading the blank form, the first time.



DropDownList in the partial view



        <div class="form-group col-md-6">
@Html.LabelFor(model => model.SeguroNombre, htmlAttributes: new { @class = "titulocampo" })
<select id="SeguroNombre" name="SeguroNombre" class="form-control"><option value=""></option></select>
@Html.ValidationMessageFor(model => model.SeguroNombre, "", new { @class = "text-danger" })
</div>


With this script, the dropdowlist is loaded, I call it from the main view in the document.ready event (it's works perfectly)



function llenaDropDownSeguros(url, valor) {

var data = { nombre: valor };
$.post(url, data).done(function (data) {
if (data.isError) {
muestraError(data.Titulo, data.Mensaje);
} else {
for (var i = 0; i < data.length; i++) {
$('#SeguroNombre').append('<option value=' + data[i].codigoSeguro + '>' + data[i].descripcion + '</option > ');
}
}
});


};



If the user wants to "copy" the information of the previous form, press a button that executes the following function js to go to the server, search the data and return the same partial view, but with the corresponding fields loaded. Re render?



Script to "copy" data



function loadPartial(url, valor) {
$("#esperar").show();
var data = { cedula: valor };
$.post(url, data).done(function (data) {
if (!data.isError) {
$("#esperar").hide();
$("#partialView").html(data);
} else {
$("#esperar").hide();
muestraError(data.Titulo, data.Mensaje);
}
}).fail(manejarErrorAjax);


};



What is the problem?



After the copy button is pressed and the partial view is reloaded with the "copied" data, the dropdownlist items are no longer there. I understand that they are lost, because of course, when doing a partial view reloaded, that dropdown comes empty, that I understood. What I do not understand is because, after reloading that partial view, there is no way I can fill the dropdowlist again. By test I made a change and in the click event of the ddl, I called the loadPartial function to see if it worked, but even though in the browser console, it is seen that the function is executed and the data object takes 94 values, these they are not loaded to the dll.



Can you help me with this problem?










share|improve this question























  • Where do you call the llenaDropDownSeguros() when you 'copy' the data? And why are you doing this instead of strongly binding your <select> to the model?

    – user3559349
    Nov 13 '18 at 23:36











  • Is there a reason why you are not using the select tag helper to render the dropdown ? If you do that, you can render the same dropdown in the partial view when it is requested from the ajax call. If not, you need to call the method which populates the select element inside your done handler again after the html method call. See this

    – Shyju
    Nov 13 '18 at 23:40













  • Well, if it does not appear in the code to "copy" the data, it is because that call is not included, why is it not included? I do not know how to do it. I wanted to run, test, fillDropDownSecure in the click event of the ddl, but it does not work either. The <select> I'll correct it ... Any suggestions regarding the problem?

    – Octavio David Peñuela Muñoz
    Nov 13 '18 at 23:49











  • Why is no one commenting about using another language in the codebase? It gets a bit harder to look at a code written in another human language.

    – Abana Clara
    Nov 13 '18 at 23:59











  • @Shyju You can help me with this: When I do scafollding to the controller, the field that I need as a dropdownlist places it as an editorfor, how do I convert that to a dropdownlistfor? taking into account that the ddl items do not come from the model, they come from a web service. –

    – Octavio David Peñuela Muñoz
    Nov 14 '18 at 0:23
















0















I have the following functionality: A user registers a series of data in a form, after sending the form and saving it in the database, it is redirected to a second form, where it must load the rest of the information, it is possible that in this second form, contains a lot of values of the first form, but this is not always the case, that is why in this second form there is a button that allows "copy" the data of the first form, to reduce data entry.



As I did?



I created a main view, where the form is loaded as a partial view with the empty model fields, so that the user can enter the information if it is not the same as the first form
Main View:



    <div id="partialView">
@Html.Partial("_CreatePartialResponsable", Model)
</div>


In the form that contains the partial view, there is a dropdowlist that is filled through a web service. This dropdow is filled correctly when loading the blank form, the first time.



DropDownList in the partial view



        <div class="form-group col-md-6">
@Html.LabelFor(model => model.SeguroNombre, htmlAttributes: new { @class = "titulocampo" })
<select id="SeguroNombre" name="SeguroNombre" class="form-control"><option value=""></option></select>
@Html.ValidationMessageFor(model => model.SeguroNombre, "", new { @class = "text-danger" })
</div>


With this script, the dropdowlist is loaded, I call it from the main view in the document.ready event (it's works perfectly)



function llenaDropDownSeguros(url, valor) {

var data = { nombre: valor };
$.post(url, data).done(function (data) {
if (data.isError) {
muestraError(data.Titulo, data.Mensaje);
} else {
for (var i = 0; i < data.length; i++) {
$('#SeguroNombre').append('<option value=' + data[i].codigoSeguro + '>' + data[i].descripcion + '</option > ');
}
}
});


};



If the user wants to "copy" the information of the previous form, press a button that executes the following function js to go to the server, search the data and return the same partial view, but with the corresponding fields loaded. Re render?



Script to "copy" data



function loadPartial(url, valor) {
$("#esperar").show();
var data = { cedula: valor };
$.post(url, data).done(function (data) {
if (!data.isError) {
$("#esperar").hide();
$("#partialView").html(data);
} else {
$("#esperar").hide();
muestraError(data.Titulo, data.Mensaje);
}
}).fail(manejarErrorAjax);


};



What is the problem?



After the copy button is pressed and the partial view is reloaded with the "copied" data, the dropdownlist items are no longer there. I understand that they are lost, because of course, when doing a partial view reloaded, that dropdown comes empty, that I understood. What I do not understand is because, after reloading that partial view, there is no way I can fill the dropdowlist again. By test I made a change and in the click event of the ddl, I called the loadPartial function to see if it worked, but even though in the browser console, it is seen that the function is executed and the data object takes 94 values, these they are not loaded to the dll.



Can you help me with this problem?










share|improve this question























  • Where do you call the llenaDropDownSeguros() when you 'copy' the data? And why are you doing this instead of strongly binding your <select> to the model?

    – user3559349
    Nov 13 '18 at 23:36











  • Is there a reason why you are not using the select tag helper to render the dropdown ? If you do that, you can render the same dropdown in the partial view when it is requested from the ajax call. If not, you need to call the method which populates the select element inside your done handler again after the html method call. See this

    – Shyju
    Nov 13 '18 at 23:40













  • Well, if it does not appear in the code to "copy" the data, it is because that call is not included, why is it not included? I do not know how to do it. I wanted to run, test, fillDropDownSecure in the click event of the ddl, but it does not work either. The <select> I'll correct it ... Any suggestions regarding the problem?

    – Octavio David Peñuela Muñoz
    Nov 13 '18 at 23:49











  • Why is no one commenting about using another language in the codebase? It gets a bit harder to look at a code written in another human language.

    – Abana Clara
    Nov 13 '18 at 23:59











  • @Shyju You can help me with this: When I do scafollding to the controller, the field that I need as a dropdownlist places it as an editorfor, how do I convert that to a dropdownlistfor? taking into account that the ddl items do not come from the model, they come from a web service. –

    – Octavio David Peñuela Muñoz
    Nov 14 '18 at 0:23














0












0








0








I have the following functionality: A user registers a series of data in a form, after sending the form and saving it in the database, it is redirected to a second form, where it must load the rest of the information, it is possible that in this second form, contains a lot of values of the first form, but this is not always the case, that is why in this second form there is a button that allows "copy" the data of the first form, to reduce data entry.



As I did?



I created a main view, where the form is loaded as a partial view with the empty model fields, so that the user can enter the information if it is not the same as the first form
Main View:



    <div id="partialView">
@Html.Partial("_CreatePartialResponsable", Model)
</div>


In the form that contains the partial view, there is a dropdowlist that is filled through a web service. This dropdow is filled correctly when loading the blank form, the first time.



DropDownList in the partial view



        <div class="form-group col-md-6">
@Html.LabelFor(model => model.SeguroNombre, htmlAttributes: new { @class = "titulocampo" })
<select id="SeguroNombre" name="SeguroNombre" class="form-control"><option value=""></option></select>
@Html.ValidationMessageFor(model => model.SeguroNombre, "", new { @class = "text-danger" })
</div>


With this script, the dropdowlist is loaded, I call it from the main view in the document.ready event (it's works perfectly)



function llenaDropDownSeguros(url, valor) {

var data = { nombre: valor };
$.post(url, data).done(function (data) {
if (data.isError) {
muestraError(data.Titulo, data.Mensaje);
} else {
for (var i = 0; i < data.length; i++) {
$('#SeguroNombre').append('<option value=' + data[i].codigoSeguro + '>' + data[i].descripcion + '</option > ');
}
}
});


};



If the user wants to "copy" the information of the previous form, press a button that executes the following function js to go to the server, search the data and return the same partial view, but with the corresponding fields loaded. Re render?



Script to "copy" data



function loadPartial(url, valor) {
$("#esperar").show();
var data = { cedula: valor };
$.post(url, data).done(function (data) {
if (!data.isError) {
$("#esperar").hide();
$("#partialView").html(data);
} else {
$("#esperar").hide();
muestraError(data.Titulo, data.Mensaje);
}
}).fail(manejarErrorAjax);


};



What is the problem?



After the copy button is pressed and the partial view is reloaded with the "copied" data, the dropdownlist items are no longer there. I understand that they are lost, because of course, when doing a partial view reloaded, that dropdown comes empty, that I understood. What I do not understand is because, after reloading that partial view, there is no way I can fill the dropdowlist again. By test I made a change and in the click event of the ddl, I called the loadPartial function to see if it worked, but even though in the browser console, it is seen that the function is executed and the data object takes 94 values, these they are not loaded to the dll.



Can you help me with this problem?










share|improve this question














I have the following functionality: A user registers a series of data in a form, after sending the form and saving it in the database, it is redirected to a second form, where it must load the rest of the information, it is possible that in this second form, contains a lot of values of the first form, but this is not always the case, that is why in this second form there is a button that allows "copy" the data of the first form, to reduce data entry.



As I did?



I created a main view, where the form is loaded as a partial view with the empty model fields, so that the user can enter the information if it is not the same as the first form
Main View:



    <div id="partialView">
@Html.Partial("_CreatePartialResponsable", Model)
</div>


In the form that contains the partial view, there is a dropdowlist that is filled through a web service. This dropdow is filled correctly when loading the blank form, the first time.



DropDownList in the partial view



        <div class="form-group col-md-6">
@Html.LabelFor(model => model.SeguroNombre, htmlAttributes: new { @class = "titulocampo" })
<select id="SeguroNombre" name="SeguroNombre" class="form-control"><option value=""></option></select>
@Html.ValidationMessageFor(model => model.SeguroNombre, "", new { @class = "text-danger" })
</div>


With this script, the dropdowlist is loaded, I call it from the main view in the document.ready event (it's works perfectly)



function llenaDropDownSeguros(url, valor) {

var data = { nombre: valor };
$.post(url, data).done(function (data) {
if (data.isError) {
muestraError(data.Titulo, data.Mensaje);
} else {
for (var i = 0; i < data.length; i++) {
$('#SeguroNombre').append('<option value=' + data[i].codigoSeguro + '>' + data[i].descripcion + '</option > ');
}
}
});


};



If the user wants to "copy" the information of the previous form, press a button that executes the following function js to go to the server, search the data and return the same partial view, but with the corresponding fields loaded. Re render?



Script to "copy" data



function loadPartial(url, valor) {
$("#esperar").show();
var data = { cedula: valor };
$.post(url, data).done(function (data) {
if (!data.isError) {
$("#esperar").hide();
$("#partialView").html(data);
} else {
$("#esperar").hide();
muestraError(data.Titulo, data.Mensaje);
}
}).fail(manejarErrorAjax);


};



What is the problem?



After the copy button is pressed and the partial view is reloaded with the "copied" data, the dropdownlist items are no longer there. I understand that they are lost, because of course, when doing a partial view reloaded, that dropdown comes empty, that I understood. What I do not understand is because, after reloading that partial view, there is no way I can fill the dropdowlist again. By test I made a change and in the click event of the ddl, I called the loadPartial function to see if it worked, but even though in the browser console, it is seen that the function is executed and the data object takes 94 values, these they are not loaded to the dll.



Can you help me with this problem?







javascript asp.net-mvc razor






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 23:27









Octavio David Peñuela MuñozOctavio David Peñuela Muñoz

103




103













  • Where do you call the llenaDropDownSeguros() when you 'copy' the data? And why are you doing this instead of strongly binding your <select> to the model?

    – user3559349
    Nov 13 '18 at 23:36











  • Is there a reason why you are not using the select tag helper to render the dropdown ? If you do that, you can render the same dropdown in the partial view when it is requested from the ajax call. If not, you need to call the method which populates the select element inside your done handler again after the html method call. See this

    – Shyju
    Nov 13 '18 at 23:40













  • Well, if it does not appear in the code to "copy" the data, it is because that call is not included, why is it not included? I do not know how to do it. I wanted to run, test, fillDropDownSecure in the click event of the ddl, but it does not work either. The <select> I'll correct it ... Any suggestions regarding the problem?

    – Octavio David Peñuela Muñoz
    Nov 13 '18 at 23:49











  • Why is no one commenting about using another language in the codebase? It gets a bit harder to look at a code written in another human language.

    – Abana Clara
    Nov 13 '18 at 23:59











  • @Shyju You can help me with this: When I do scafollding to the controller, the field that I need as a dropdownlist places it as an editorfor, how do I convert that to a dropdownlistfor? taking into account that the ddl items do not come from the model, they come from a web service. –

    – Octavio David Peñuela Muñoz
    Nov 14 '18 at 0:23



















  • Where do you call the llenaDropDownSeguros() when you 'copy' the data? And why are you doing this instead of strongly binding your <select> to the model?

    – user3559349
    Nov 13 '18 at 23:36











  • Is there a reason why you are not using the select tag helper to render the dropdown ? If you do that, you can render the same dropdown in the partial view when it is requested from the ajax call. If not, you need to call the method which populates the select element inside your done handler again after the html method call. See this

    – Shyju
    Nov 13 '18 at 23:40













  • Well, if it does not appear in the code to "copy" the data, it is because that call is not included, why is it not included? I do not know how to do it. I wanted to run, test, fillDropDownSecure in the click event of the ddl, but it does not work either. The <select> I'll correct it ... Any suggestions regarding the problem?

    – Octavio David Peñuela Muñoz
    Nov 13 '18 at 23:49











  • Why is no one commenting about using another language in the codebase? It gets a bit harder to look at a code written in another human language.

    – Abana Clara
    Nov 13 '18 at 23:59











  • @Shyju You can help me with this: When I do scafollding to the controller, the field that I need as a dropdownlist places it as an editorfor, how do I convert that to a dropdownlistfor? taking into account that the ddl items do not come from the model, they come from a web service. –

    – Octavio David Peñuela Muñoz
    Nov 14 '18 at 0:23

















Where do you call the llenaDropDownSeguros() when you 'copy' the data? And why are you doing this instead of strongly binding your <select> to the model?

– user3559349
Nov 13 '18 at 23:36





Where do you call the llenaDropDownSeguros() when you 'copy' the data? And why are you doing this instead of strongly binding your <select> to the model?

– user3559349
Nov 13 '18 at 23:36













Is there a reason why you are not using the select tag helper to render the dropdown ? If you do that, you can render the same dropdown in the partial view when it is requested from the ajax call. If not, you need to call the method which populates the select element inside your done handler again after the html method call. See this

– Shyju
Nov 13 '18 at 23:40







Is there a reason why you are not using the select tag helper to render the dropdown ? If you do that, you can render the same dropdown in the partial view when it is requested from the ajax call. If not, you need to call the method which populates the select element inside your done handler again after the html method call. See this

– Shyju
Nov 13 '18 at 23:40















Well, if it does not appear in the code to "copy" the data, it is because that call is not included, why is it not included? I do not know how to do it. I wanted to run, test, fillDropDownSecure in the click event of the ddl, but it does not work either. The <select> I'll correct it ... Any suggestions regarding the problem?

– Octavio David Peñuela Muñoz
Nov 13 '18 at 23:49





Well, if it does not appear in the code to "copy" the data, it is because that call is not included, why is it not included? I do not know how to do it. I wanted to run, test, fillDropDownSecure in the click event of the ddl, but it does not work either. The <select> I'll correct it ... Any suggestions regarding the problem?

– Octavio David Peñuela Muñoz
Nov 13 '18 at 23:49













Why is no one commenting about using another language in the codebase? It gets a bit harder to look at a code written in another human language.

– Abana Clara
Nov 13 '18 at 23:59





Why is no one commenting about using another language in the codebase? It gets a bit harder to look at a code written in another human language.

– Abana Clara
Nov 13 '18 at 23:59













@Shyju You can help me with this: When I do scafollding to the controller, the field that I need as a dropdownlist places it as an editorfor, how do I convert that to a dropdownlistfor? taking into account that the ddl items do not come from the model, they come from a web service. –

– Octavio David Peñuela Muñoz
Nov 14 '18 at 0:23





@Shyju You can help me with this: When I do scafollding to the controller, the field that I need as a dropdownlist places it as an editorfor, how do I convert that to a dropdownlistfor? taking into account that the ddl items do not come from the model, they come from a web service. –

– Octavio David Peñuela Muñoz
Nov 14 '18 at 0:23












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291004%2fdropdownitem-doesnt-load-items-after-updatejavascript-partial-view%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291004%2fdropdownitem-doesnt-load-items-after-updatejavascript-partial-view%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine