I have this routine using Razor from C #. 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 have this Modal in a _PartialModalLayout
that I call with @Html.Partial()
. The idea of working is when I click on Cliente.Nome
it will open Modal with some information.
Here is 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 data-id
, but I could not. 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
to the modal how can I use this id in the modal? I tried something like, @Model.Mensagem[id].Conteudo
but it does not recognize the id variable.