I have a view / action that uses meto [HTTPGET], when I click on the url for the first time, just to open the view, theoretically it was to be null, but it is coming prefilled.
Images of the first requisition that was to come null:
Andeventhoughtheyarefilled,theygothroughIfandreturntheviewtobefilled:
Andevenafterpopulatingandsubmittingvariables,theydonotcomefromtheviewtothecontrol,butthevariablesarefilledinjustliketheimagesabove,withdatesandrandomIds.
MyAction:
publicActionResultDcvPorCombustivel(DateTime?dataInicio,DateTime?dataFim,int?IdCombustivel){Combustivelcomb=newCombustivel();if(dataInicio==null&&dataFim==null&&IdCombustivel==null){ViewBag.IdCombustivel=newSelectList(db.DbCombustivel,"IdCombustivel", "Descricao", comb.IdCombustivel);
return View();
}
IList<Vr> ListaDeSolicitacoes = new List<Vr>();
ListaDeSolicitacoes = vrAplicacao.DcvPorCombustivel(dataInicio, dataFim, IdCombustivel);
ViewBag.IdCombustivel = new SelectList(db.DbCombustivel, "IdCombustivel", "Descricao", comb.IdCombustivel);
return View(ListaDeSolicitacoes);
}
My View:
@model IEnumerable<GaragemModel.Vr>
@{
ViewBag.Title = "Dcv Por Combustivel";
Layout = "~/Views/Shared/_LayoutRelatorios.cshtml";
}
<div class="panel-heading text-center">
<h3>
DCV - Demonstrativo dos custos das Viaturas / Combustível
</h3>
</div>
<div class="panel-heading">
<ul class="list-inline">
<li> <h4>Período:</h4></li>
<li>@ViewBag.dataInicial Até</li>
<li> @ViewBag.dataFinal</li>
</ul>
</div>
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>
Descrição
</th>
<th>
Placa
</th>
<th>
Combustivel
</th>
<th>
Consumo
</th>
<th>
Gasto
</th>
</tr>
</thead>
<tbody>
@if (Model != null)
{
foreach (var item in Model)
{
<tr class="odd gradeX">
<td>
@Html.DisplayFor(modelItem => item.Veiculo.Descricao)
</td>
<td>
@Html.DisplayFor(modelItem => item.Veiculo.Placa)
</td>
<td>
@Html.DisplayFor(modelItem => item.Veiculo.Combustivel.Descricao)
</td>
<td>
@Html.DisplayFor(modelItem => item.Mv.CombustivelAbastecido) Litros
</td>
<td>
R$ @Html.DisplayFor(modelItem => item.Veiculo.Combustivel.Preco)
</td>
</tr>
}
<tr class="well" style="font-weight:bold">
<td>Total</td>
<td></td>
<td></td>
<td></td>
<td>R$ @ViewBag.Total</td>
</tr>
}
</tbody>
</table>
<div class="modal fade" id="exemplomodal" tabindex="-1" role="dialog" aria-
labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg" role="document">
<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="gridSystemModalLabel">Selecione a Data</h4>
</div>
<div class="modal-body">
<div class="panel panel-default">
<div class="panel-heading">
Relatório De Solicitações Por Período/ Combustivel
</div>
<div class="panel-body">
<form method="post" action="/Vr/DcvPorCombustivel" class="form-horizontal">
<div class="form-group">
<label for="dataInicial" class="col-sm-3 control-label">Data Inicial:</label>
<div class="col-sm-7">
<input type="date" class="form-control" id="dataInicial" name="dataInicio" required>
</div>
</div>
<div class="form-group">
<label for="dataFinal" class="col-sm-3 control-label">Data Final</label>
<div class="col-sm-7">
<input type="date" class="form-control" id="dataFinal" name="dataFim" required>
</div>
</div>
<div class="form-group">
@Html.LabelForModel("Combustivel:", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("IdCombustivel", null, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">Gerar Relatório</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
</div>
</div>
</div>
@section scripts {
<!-- jquery -->
<script src="~/Scripts/jquery-1.11.0.min.js"></script>
@*<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>*@
<!-- bootstrap -->
<script src="~/Scripts/bootstrap.js"></script>
<!-- chamada da função -->
<script type="text/javascript">
$(window).load(function () {
$('#exemplomodal').modal('show');
});
</script>
}
The form is populated in a Modal.