1
I have a register in the system that I am developing that will have repeated fields, I would like to get help in this implementation.
This screen is called Sequence which has the following fields
Date
Numero Sequencia
Lot
Name = Side A | Type | Camera
Name = Side B | Type | Camera
All the registration of Sequencia that will be carried out will always have Side A and Side B.
I created a class so that Views can see the classes corresponding to the register.
Class Sequenciaviewmodel
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace GerenciamentoDeQuartos.Models
{
public class SequenciaViewModel
{
public SequenciaViewModel()
{
Lado_A.Nome = "Lado A";
Lado_B.Nome = "Lado B";
}
public Lote Lote { get; set; }
public List<Lote> LoteList { get; set; }
public Sequencia Sequencia { get; set; }
public List<Sequencia> SequenciaList { get; set; }
[Display(Name = "Tipo Lado A")]
[Required(ErrorMessage = "O Campo {0} é requirido!")]
[Range(1, double.MaxValue, ErrorMessage = "Selecione o {0} corretamente!")]
public Lado Lado_A { get; set; }
[Display(Name = "Tipo Lado B")]
[Required(ErrorMessage = "O Campo {0} é requirido!")]
[Range(1, double.MaxValue, ErrorMessage = "Selecione o {0} corretamente!")]
public Lado Lado_B { get; set; }
public List<Lado> LadoList { get; set; }
[Display(Name = "Camara A")]
[Required(ErrorMessage = "O Campo {0} é requirido!")]
[Range(1, double.MaxValue, ErrorMessage = "Selecione o {0} corretamente!")]
public Camara Camara_A { get; set; }
[Display(Name = "Camara B")]
[Required(ErrorMessage = "O Campo {0} é requirido!")]
[Range(1, double.MaxValue, ErrorMessage = "Selecione o {0} corretamente!")]
public Camara Camara_B { get; set; }
public List<Camara> CamaraList { get; set; }
}
}
Sequence Registration View ( Create )
@model GerenciamentoDeQuartos.Models.SequenciaViewModel
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Sequencia</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.Lado_A.Nome)
@Html.HiddenFor(model => model.Lado_B.Nome)
<div class="form-group">
@Html.LabelFor(model => model.Sequencia.DataAbate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Sequencia.DataAbate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Sequencia.DataAbate, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Sequencia.NumeroSequencia, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Sequencia.NumeroSequencia, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Sequencia.NumeroSequencia, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Sequencia.Lote, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Sequencia.Lote, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Sequencia.Lote, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Lado_A.Nome, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Lado_A.Nome, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Lado_A.Nome, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Lado_A, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("TipoLadoId", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Lado_A.TipoLadoId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Camara_A, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("CamaraId", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Lado_A.CamaraId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Lado_B.Nome, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Lado_A.Nome, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Lado_A.Nome, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Lado_B.TipoLadoId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("TipoLadoId", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Lado_B.TipoLadoId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Camara_B, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("CamaraId", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Lado_B.CamaraId, "", new { @class = "text-danger" })
</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>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>