1
I can’t carry a partialview in a div !
<fieldset>
<legend>Contato:</legend>
@Html.Label("Tipo Contato: ")
@Html.DropDownListFor(t => t.CodTipoContato, Model.TipoContatoList, new { id = "tipoContato", name = "tipoContato", onchange = "CarregarPartialView()" })
<div id="result">
@if(Model!=null)
{
if (Model.CodTipoContato == 10)
{
Html.RenderPartial("_ContatoEmailFields");
}
else if(Model.CodTipoContato==0)
{
Html.RenderPartial("_EmptyView");
}
else
{
Html.RenderPartial("_ContatoTelefoneFields");
}
}
<script type="text/javascript">
function CarregarPartialView(CodTipoContato){
var codTipoContato = $("#tipoContato").val();
$.ajax(
{
type: "GET",
url: "TipoContato",
data: "CodTipoContato="+codTipoContato,
sucess: function (result) { $('#resultado').html(result)}
});
};
</script>
public PartialViewResult TipoContato(int CodTipoContato)
{
var tcList = ConsultaRepositorio.ObterTipoContato();
var codTipoContato = CodTipoContato;
var tipoContatoVM = new SuperViewModel()
{
TipoContatoList = Extentions.ObterTipoContatosList(tcList),
CodTipoContato=codTipoContato
};
return PartialView("_ContatoFields",tipoContatoVM);
}
What happens? Some mistake?
– André Ribeiro
the partialview is not loaded inside the div!
– Hans Miller
In the callback of your ajax call you are using
$('#resultado').html(result)
but in your HTMLdiv
has the idresult
. Is that not the problem?– André Ribeiro
not that not ,corrected and continue without carrying the partialview inside the div! does not carry anything!
– Hans Miller
What appears in the tab
Network
browser developer tools (assuming you are using Firefox or Chrome)?– André Ribeiro
Pow appears my selected partialview!! but pq does not load inside the page??
– Hans Miller
You have to look at the tab
Network
(or Network) and see what the ajax request returns.– André Ribeiro