3
I have this routine using the C#Razor. It lists my messages :
Code:
@for (int i = 0; i < 3; i++)
{
<div class="box-body" style="line-height:15px">
<ul class=" products-list products-list">
<li class="timeline-item">
<div class="product-img">
<img src="/Content/imagens/principais/no-user.png" alt="Product Image" style="height:40px">
</div>
<div class="product-info">
<a href="" class="product-title" data-toggle="modal" data-target="#myModal">
@if (Model.Mensagens[i].Cliente.Nome != null && Model.Mensagens[i].Cliente.Nome.Length > 0)
{
@Model.Mensagens[i].Cliente.Nome;
}
else
{
@Model.Mensagens[i].Cliente.Email;
}
@if (Model.Mensagens[i].Visualizada == false)
{
<span class="label label-primary pull-right">Não lida</span>
}
</a>
<span class="product-description">
@Model.Mensagens[i].Conteudo
</span>
</div>
</li>
</ul>
</div>
Notice the link:
<a href="" class="product-title" data-toggle="modal" data-target="#myModal">
I got this Modal in a _PartialModalLayout
that I call with @Html.Partial()
. The idea of working is when I click on Cliente.Nome
he will open Modal with some information.
Here is this part of my Modal (Remembering that it is in a separate file)
<div class="box box-info">
<div class="box-body">
<form action="#" method="post">
<div class="form-group">
<h4>Cliente</h4>
<input type="email" disabled value="@if (@Model.Mensagens[id].Cliente.Nome != null)
{ @Model.Mensagens[id].Cliente.Nome}else{ @Model.Mensagens[id].Cliente.Email}"
class=" form-control" name="emailto" placeholder="Email to:">
</div>
<h4>Mensagem</h4>
<div>
<textarea disabled id="MensagemRecebida" style="min-width: 100%;height:120px;display:block">@Model.Mensagens[id].Conteudo</textarea>
</div>
<div>
<textarea id="EscreverMensagem" style="min-width: 100%;height:150px;margin-top:20px " placeholder="Digite sua mensagem..."></textarea>
</div>
</form>
</div>
I tried to use the data-id
, but I couldn’t. How can I open the modal by passing the message and client information?
EDIT- I am using a script the following script :` $(Document). ready(Function () {
$('a[data-toggle=modal], button[data-toggle=modal]').click(function () {
var data_id = '';
if (typeof $(this).data('id') !== 'undefined') {
data_id = $(this).data('id');
}
$('#myModal').val(data_id);
})
});
`
Assuming this is the right script, after I pass this data-id
for the modal as I can use this id in the modal ? I tried something like, @Model.Mensagem[id].Conteudo
but does not recognize the id variable.
See if any of these help: http://answall.com/questions/130803/passar-id-de-um-dado-de-uma-tabela-para-a-modal-resolvido or http://answall.com/questions/130169/tabela-edit%C3%a1vel-em-php
– Miguel
Hey How are you calling the modal ?
– paulo_tully
I will check this post Miguel , and did an Edit paulo_tully, Thanks for your attention .
– William Cézar
Possible duplicate of Switch varialvel to modal
– William Aparecido Brandino
I made a change, check it out, I’m reading the posts they sent me to see if I can fix it.
– William Cézar
William Cézar, I tried to edit your post to be clearer, see if I captured what you wanted.
– Anthony Accioly
Yes basically that’s it Anthony, as I have a for the listing of the message I do not know how to pass the customer index to Modal , for me to retrieve his information there.
– William Cézar
I did an update reflecting a little more my doubt, if any can help me, so far I could not solve.
– William Cézar
I got a solution and I answered my question, take a look at the answer, in case you’re confused I try to tidy up.
– William Cézar