When looking for how to render a partialView
in a modal bootstrap , I found this link: Using Bootstrap Modal window as PartialView , but I need to make a POST
request by clicking the button that opens the modal. That is, I need to send the current modelView
from my main view to the partial view .
Could someone tell me how to adapt the "GetGameListing" example of the above link to reach 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");
}
});
});