Objective : Manipulate 2 models in the view using a ViewModel.
I made a ViewModel to encapsulate the 2 models, but I can not use one of them.
ViewModel:
public class BoletoConfigViewModel
{
public Boleto Boletos { get; set; }
public ConfigCliente Config { get; set; }
}
Controller:
var config = db.Config
.SingleOrDefault(x => x.ClienteId == 3); //consulta com o DataBase
// I'm not sure this would be the best way to do this query.
var viewModel = new BoletoConfigViewModel
{
Boletos = new Boleto(),
Config = config
};
return View(viewModel);
Na view:
@model WMB.MVC.Extranet.ViewModel.BoletoConfigViewModel
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Boletos.DataVencimento, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Boletos.DataVencimento, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Boletos.DataVencimento, "", new { @class = "text-danger" })
</div>
</div>
..//bastante codigo acima criado pelo Scanffolding...
Agora onde da problema
<div>Configuração.:</div> @Html.DisplayFor(model => model.Config.cur_Configuracao.ToString());
I was asked to do with a partial view, etc ... But for learning purposes and wondering what else I'll need this is not possible?
Error:
Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions
Riga 85: <div>Configuração.:</div> @Html.DisplayFor(model => model.Config.cur_Configuracao.ToString());