0
When searching for how to render a partialView
in a modal bootstrap, found this link: Using Bootstrap Modal window as Partialview, only I need to make a request POST
by clicking the button that opens the modal. That is, I need to send the modelView
current of my main view to the partial view.
Could someone tell me how to adapt the "Getgamelisting" example from the link above to achieve my goal?
EDIT 1: Adding Code.
Model:
public class SearchByCooperator
{
[DisplayName("Nome")]
public string m_Nome { get; set; }
[DisplayName("Cota")]
public string m_Cota { get; set; }
[DisplayName("Cartão")]
public string m_Cartao { get; set; }
[DisplayName("Cidade")]
public string m_Cidade{ get; set; }
public string m_LojaAtendimento { get; set; }
[DisplayName("Acompanhantes")]
public List<NomeIdCooperado> m_Acompanhantes { get; set; }
[DisplayName("Data Visita")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime m_DataVisita { get; set; }
}
Controller:
[HttpPost]
public ActionResult GerarEtiquetas(SearchByCooperator v_model)
{
}
View:
<div class="span">
<button id='gerar'>Gerar</button>
</div>
<!-- Modal -->
<div class="modal fade " id="myModal" tabindex="-1" role="dialog" aria- labelledby="myModalLabel" aria-hidden="true" style="width: 750px; margin-left: -375px;" data-url='@Url.Action("GerarEtiquetas")'>
<div class="modal-dialog modal-lg">
<div class="modal-content" id="etiqueta_container">
</div>
</div>
</div>
Script:
$('#gerar').click(function () {
var url = $('#myModal').data('url');
var data = '@COOPA.Core.Common.JsonUtil.ToJson(Model)';
$.ajax({
type: "POST",
url: url,
data: JSON.stringify(data),
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (data) {
$('#etiqueta_container').html(data);
$('#myModal').modal('show');
},
error: function (args) {
alert("erro");
}
});
});
have tried instead of using the
$.get()
use the$.post()
?– Tafarel Chicotti