0
I have a View where I return the data of a user, and I need to call another view, to save data, through a modal. The problem, is that they are two views of different controllers, so when calling, by means of a Partialview i get a declaration error.
The model item passed into the dictionary is of type 'PortalRH.DomainModel.Entities.Usuario', but this dictionary requires a model item of type 'PortalRH.DomainModel.Entities.Divergente'.
My index:
@model PortalRH.DomainModel.Entities.Usuario
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Relatar Divergência
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
@Html.Partial("~/Views/Divergente/Relatar.cshtml")
</div>
</div>
</div>
</div>
<!--ABAS-->
<div class="container">
<div class="col-lg-12">
<ul class="nav nav-pills faq-cat-tabs">
<li class="active"><a data-toggle="tab" href="#sectionA">Pessoal</a></li>
<li><a data-toggle="tab" href="#sectionD">Documentos</a></li>
<li><a data-toggle="tab" href="#sectionB">Endereço</a></li>
<li><a data-toggle="tab" href="#sectionC">Dados Profissionais</a></li>
</ul>
</div>
<div class="col-lg-12">
<div class="tab-content">
<div id="sectionA" class="tab-pane fade in active">
<br /><br />
@Html.Partial("_DadosPessoais")
</div>
<div id="sectionB" class="tab-pane fade">
<br /><br />
@Html.Partial("_Endereco")
</div>
<div id="sectionC" class="tab-pane fade">
<br /><br />
@Html.Partial("_DadosProfissionais")
</div>
<div id="sectionD" class="tab-pane fade">
<br /><br />
@Html.Partial("_Documentos")
</div>
</div>
</div>
</div>
<div class="container body-content">
<hr />
<div align="center">
<footer>
<p>© @DateTime.Now.Year - Portal RH - <a href="http://www.vilavelha.es.gov.br" target="_blank">Prefeitura Municipal de Vila Velha</a></p>
</footer>
</div>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
The View I need to call through the modal:
@model PortalRH.DomainModel.Entities.Divergente
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="row">
<div class="col-md-2">
@TempData["Mensagem"]
</div>
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-heading">
<h5><strong>Dependente(s)</strong></h5>
</div>
<table class="table">
<thead>
<tr>
<td></td>
<th>CAMPO</th>
<th>INFORMAÇÃO CORRETA</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="3" align="center">DADOS PESSOAIS</td>
</tr>
<tr>
<td><input type="checkbox" class="cb" data-id="nmMae"></td>
<td> Data de Nascimento</td>
<td><input type="text" data-id="nmMae" disabled class="form-control" name="nmMae"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
}
Just adding, I have the two pages working perfectly( in each separate view), I only need one to appear in a modal, on the same page.
partial is a different model, with user functionality saved in the database, some divergence in its information, for the administrator to review and change, if correct. The User and Divergent entities have no relationship, I just need to show through a Modal, to make the application easier to be used by the user.
Just adding, I have the two pages working perfectly( in each separate view), I only need one to appear in a modal, on the same page.
Am I trying to do it the right way? Or is there another way to get the same result?
The information that will be displayed on
PartialView
are in whichModel
?– Leonel Sanches da Silva
@Ciganomorrisonmendez I edited the question, with the models in their certain Views
– Randrade
I still don’t understand.
Index
hasDivergente
asModel
. ToPartial
also?– Leonel Sanches da Silva
@Ciganomorrisonmendez No. Index has User as Model, and partial has Divergent. I need to show both in the same view, just to make it easier for the user to use the application.
– Randrade
And what is the relationship of
Usuario
withDivergente
, if there is any?– Leonel Sanches da Silva
@None. What I’m wanting to do is when the person clicks the button REPORT DIVERGENCE open a modal with the "Divergent" view, so the user can edit it. Because the way it is, it is redirected to another page.
– Randrade