-1
I need a help, I can not solve a stop, when I load a web screen, I have an add button that create 3 html fields and so will add one at the bottom of the other, but it’s giving way, because I have my page Partialcomposicaoemail.cshtml below with the fields:
@using Itau.DPE.MesaPrecos.DAO.Models;
@model List<TB_Campos_Email>
@if (Model != null && Model.Count > 0)
{
<div class="col-md-12">
<table class="table table-striped Exp-Table">
<tr class="table-tr">
<th style="text-align: center">Origem</th>
<th style="text-align: left">Campo</th>
<th style="text-align: left">Alias</th>
<th style="text-align: center"></th>
</tr>
@foreach (var item in Model)
{
<tr class="listCamposDinamicos">
@*Origem Campo Validador*@
<td>
<select class="selectpicker selvalorOrigem" data-live-search="true" aria-expanded="true">
<option value="@item.Origem" selected>@item.Origem 0</option>
@*<option value="0" selected></option>*@
</select>
</td>
@*Campo Validador*@
<td>
<select class="selectpicker selvalorCampo" data-live-search="true" aria-expanded="true">
<option value="@item.Valor_Campo" selected>@item.Valor_Campo 0</option>
@*<option value="0" selected></option>*@
</select>
</td>
<td class="text" style="text-align: left;" id="tdValor">
<input type="text" class="txtAlias" value="@item.Alias" style="width: 215px;" maxlength="100" aria-expanded="true" />
@*Botão Remover*@
<td class="text-center">
<a href="#" id="btn-remover-comp">
<span class="glyphicon glyphicon-trash exp-glyphicon-remove" style="font-size: large"></span>
</a>
</td>
</td>
</tr>
}
</table>
</div>
}
I have my Email.js that has the functions Getcamposdinamicogrid and Addcamposdinamico, ta giving Getcamposdinamicogrid with the error: message: "Getcamposdinamicogrid is not defined" stack: "Referenceerror: Getcamposdinamicogrid is not defined at Eval (Eval at Getcamposdinamicogrid (http://localhost:54771/Mesaprecos/Scripts/Email.js:583:9), :1:1) at Getcamposdinamicogrid (http://localhost:54771/Mesaprecos/Scripts/Email.js:583:9)At Addcamposdinamico (http://localhost:54771/Mesaprecos/Scripts/Email.js:600:32)At Htmldivelement. (http://localhost:54771/Mesaprecos/Scripts/Email.js:5:9)At Htmlbodyelement.Dispatch (http://localhost:54771/Mesaprecos/Scripts/Core/jquery-1.12.0.min. js:3:12344)At Htmlbodyelement.r.Handle (http://localhost:54771/Mesaprecos/Scripts/Core/jquery-1.12.0.min. js:3:9071)" proto: Error
function GetCamposDinamicoGrid() {
var obj = [];
debugger;
$(".listCamposDinamicos").each(function () {
var origemCampo = {};
origemCampo.origem = $('.selvalorOrigem').find(":selected").text(); //$(this).find(".selvalorOrigem").text();
origemCampo.valorCampo = $('.selvalorCampo').find(":selected").text(); //$(this).find(".selvalorCampo").text();
origemCampo.alias = $(this).find(".txtAlias").text();
obj.push(origemCampo);
});
return obj;
}
function AddCamposDinamico(){
MensagemBloqueio("Aguarde...");
var listacamposEmail = GetCamposDinamicoGrid();
debugger;
$.ajax({
type: 'POST',
url: 'Email/AddCamposDinamico',
data: { 'listCamposDinamicos': JSON.stringify(listacamposEmail) },
dataType: 'html',
cache: false,
async: true,
statusCode: {
200: function (resultado) {
DesbloquearPagina();
$('#divCamposDinamicos').slideDown();
$('#divCamposDinamicos').html(resultado);
},
99: function (resultado) {
DesbloquearPagina();
ExibirMensagem(resultado.responseText);
}
}
});
}
Function Addcamposdinamico sends to a controller below to decentralize the fields and create:
public ActionResult AddCamposDinamico(string listacamposEmail)
{
var campos = new JavaScriptSerializer().Deserialize<List<TB_Campos_Email>>(listacamposEmail);
if (campos == null)
campos = new List<TB_Campos_Email>();
campos.Add(new TB_Campos_Email { Origem = "", Valor_Campo = "", Alias = "" });
Response.StatusCode = 200;
return PartialView("PartialComposicaoEmail", campos);
}
I don’t know if this is the way I’m using in jquery to capture the selects you’ve been playing, because when you get to the line var fields = new Javascriptserializer(). Deserialize>(Mail field lists); brings error {"Value cannot be null. nName of parameter: input"} I have tried to make several changes, but it remains, I am waiting for a help.