I'm getting the following error:
'AddEmployeeViewModel' does not contain a definition for 'OfficeEmployee' and in the extension method 'OfficeEmployee' accepting the first argument of type 'AddEmployeeViewModel' could be found >
Inside the View, there is a button that opens a modal so that the user can register a Cargo
that will populate a Select Box, this position is registered individually, only on the same screen that the employee is registered. / p>
So I would like to know how I can separate the model from Cargo
and Funcionario
, since I use the same controller for both Cargo
and Funcionario
.
ThisismyAddEmployeeViewModel
:
publicclassAddEmployeeViewModel{[Required(ErrorMessage="Nome é um campo obrigatório")]
[StringLength(100, ErrorMessage = "O {0} deve ter pelo menos {2} e no máximo {1} caracteres.", MinimumLength = 3)]
[Display(Name = "Nome")]
public String Name { get; set; }
[RegularExpression(@"/^[0-9]{3}.?[0-9]{3}.?[0-9]{3}-?[0-9]{2}/", ErrorMessage = "CPF está em um formato inválido.")]
public String Cpf { get; set; }
[RegularExpression(@"^\([1-9]{2}\) (?:[2-8]|9[1-9])[0-9]{3}\-[0-9]{4}$", ErrorMessage = "Telefone está em um formato inválido.")]
public String Telephone { get; set; }
[Required(ErrorMessage = "Email é um campo obrigatório")]
[RegularExpression(@"^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$", ErrorMessage = "Email está em um formato inválido.")]
public String Email { get; set; }
public long Office { get; set; }
[Required(ErrorMessage = "Cor é um campo obrigatório")]
public String Color { get; set; }
public decimal Commission { get; set; }
public IFormFile Pic { get; set; }
public Nullable<DateTime> BirthDate { get; set; }
[RegularExpression(@"^\d{5}-\d{3}$", ErrorMessage = "CEP está em um formato inválido.")]
[Display(Name = "CEP")]
public String CEP { get; set; }
public String UF { get; set; }
public String Neighborhood { get; set; }
public String City { get; set; }
public String Address { get; set; }
public String Number { get; set; }
public String Complement { get; set; }
}
public class Office
{
public String OfficeEmployee { get; set; }
}
and this is the part of View that is giving the error:
<div class="modal fade none-border" id="cadastra-cargo">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Novo Cargo</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<form asp-route-returnUrl="@ViewData["ReturnUrl"]" id="cadastraCargoFuncionario" asp-action="AddOffice" asp-controller="Employee" method="post">
<div class="form-body">
<div class="row">
<div class="col-md-12">
<div class="form-group row">
<label class="control-label text-right col-md-3">Cargo: </label>
<div class="col-md-8">
<input type="text" asp-for="OfficeEmployee" class="form-control nome">
<span asp-validation-for="OfficeEmployee" class="text-danger"></span>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<div class="col-md-12">
<button type="button" class="btn btn-info float-r" data-dismiss="modal" onclick="$('#cadastraCargoFuncionario').submit();">Salvar</button>
<button type="button" class="btn btn-default float-l" data-dismiss="modal">Cancelar</button>
</div>
</div>
</div>
</div>