1
Guys I got a view
call Projects that brings a list of projects and need to view the information/detail of each project through a modal Bootstrap
. So I created a button that calls a function javascript
within the view
Projects:
<a data-toggle="modal" class="btn btn-default btnDetalhes" data-value="@item.Codigo">Details</a>
$(document).ready(function () {
$.ajaxSetup({ cache: false });
var id = $(this).data("value");
$(".btnDetalhes").click(function () {
$("#conteudomodal").load("/Documentos/DetalhePrj/" + id, function () {
$('#myModal').modal("show");
});
});
});
And this function calls the modal Bootstrap
:
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<div id="conteudomodal">
</div>
</div>
</div>
</div>
and through the load("/Documentos/DetalhePrj/")
calls the controller
that returns a partial view DetalhePrj
:
public PartialViewResult DetalhePrj(int id)
{
string PRJCODIGO = id.ToString();
ClienteModels ClienteAtivo = (ClienteModels)Session["EmpresaAtiva"];
PCIOSDIGITALSOAPClient soap = new PCIOSDIGITALSOAPClient();
ProjetoModel projeto = new ProjetoModel();
projeto.Codigo = PRJCODIGO;
soap.Open();
List<STRUCTPROJDETALHE> lista = soap.LSTDETALHEPRJ(projeto.Codigo, ClienteAtivo.Loja);
List<DetalhePrjModel> model = new List<DetalhePrjModel>();
foreach (STRUCTPROJDETALHE item in lista)
{
DetalhePrjModel document = new DetalhePrjModel();
document.CodigoPrj = item.CODPRJ;
document.Versao = item.VERPRJ;
document.Coord = item.COORD;
document.DescrPrj = item.DESPRJ;
model.Add(document);
}
soap.Close();
return PartialView("~/Views/Documentos/_DetalhePrj.cshtml", model);
}
The problem is that by clicking on buttom
it opens the Modal but does not bring any information/detail of the project (modal opens in white). It is as if I am not able to call the controller
but I’ve already checked and I don’t know where I’m going wrong.
Does anyone know what it can be?
Now I’m trying to pass two values through buttom for javascript:
<a data-toggle="modal" class="btn btn-default btnDetalhes" data-value="@item.Codigo" data-value2="@item.Versao">Details</a>
$(document).ready(function () {
$.ajaxSetup({ cache: false });
$(".btnDetalhes").click(function () {
var id = $(this).data("value");
var vers = $(this).data("value2");
$("#conteudomodal").load("DetalhePrj/" + id, + vers,
function () {
$('#myModal').modal("show");
});
});
});
Except that the variable vers is null, it is not pulling the value of buttom.. It is not possible to pass two values through a single buttom?
You can try changing your call a little
ajax
and not use theload
, but rather receive the return of the call and play the return in conteudomodal, using thesuccess
, knows how to do this?– Ricardo Pontual
Your
data-value
is with a line break, check if it was only in the reply post.– Leandro Angelo
Debugged and is calling the controller and everything else, the problem is that the ajax call is not getting the value of the variable id buttom, gives that the variable id is Undefined.
– Emanuele Baron
@Leandroangelo only in the post is with the line break. In the code is straight
– Emanuele Baron
The id is not picking up because it is outside the . btnDetails click block
– Leandro Angelo
@Leandroangelo did what you said and it worked. Thank you!!!
– Emanuele Baron
@Emanuelebaron I was writing the answer with that remark, but I wanted to know if your attribute was also not wrong.
– Leandro Angelo
@Emanuelebaron, you have solved?
– Leandro Angelo
@Leandroangelo still not able to pass two values for javascript, have any idea what can be?
– Emanuele Baron
But your controller receives two parameters?
– Leandro Angelo
Receives yes...
public PartialViewResult DetalhePrj(int id, int vers)
– Emanuele Baron