0
I have this code, working perfectly as I wish
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="container">
<form class="well form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.ID_Reserva)
<div class="form-group">
@Html.LabelFor(model => model.ID_Cliente, "ID_Cliente", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("ID_Cliente", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.ID_Cliente, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DataEntrada, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DataEntrada, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DataEntrada, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DataSaida, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DataSaida, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DataSaida, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TipoQuarto, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TipoQuarto, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TipoQuarto, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.NumeroQuarto, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.NumeroQuarto, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.NumeroQuarto, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.NumeroNoites, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.NumeroNoites, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.NumeroNoites, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Preço, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Preço, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Preço, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Observaçoes, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Observaçoes, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Observaçoes, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Salvar" class="btn btn-default" />
</div>
</div>
</form>
</div>
}
However, when I try to change this code from the top to this code, in order to change the format ( aesthetic reason ) give me the following error !
Code
<div class="container">
<form class="well form-horizontal" action=" " method="post" id="contact_form">
<div class="form-group">
<label class="col-md-4 control-label">Nome Cliente</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input name="Nome Cliente" class="form-control" value="@Model.Cliente.Nome">
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Data Entrada</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span>
<input name="Data Entrada" class="form-control" value="@Model.DataEntrada">
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Data Saída</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span>
<input name="Data Saída" class="form-control" value="@Model.DataSaida">
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Tipo Quarto</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-hotel"></i></span>
<input name="Tipo Quarto" class="form-control" value="@Model.TipoQuarto">
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">NºQuarto</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-hotel"></i></span>
<input name="NºQuarto" class="form-control" value="@Model.NumeroQuarto">
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">NºNoites</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-hotel"></i></span>
<input name="NºNoites" class="form-control" value="@Model.NumeroNoites">
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Preço</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-euro"></i></span>
<input name="Preço" class="form-control" value="@Model.Preço">
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Observações</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-pencil"></i></span>
<textarea class="form-control" name="Observações" value="@Model.Observaçoes"></textarea>
</div>
</div>
</div>
</form>
</div>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-4">
<button type="submit" class="btn btn-success">Editar<span class="glyphicon glyphicon-edit"></span></button>
@Html.ActionLink("Ir para a listagem de Reservas", "Index")
</div>
</div>
}
By executing this give me this mistake
Entity
namespace WebApplication.Models.BaseDados
{
using System;
using System.Collections.Generic;
public partial class Reserva
{
public int ID_Reserva { get; set; }
public int ID_Cliente { get; set; }
public System.DateTime DataEntrada { get; set; }
public Nullable<System.DateTime> DataSaida { get; set; }
public string TipoQuarto { get; set; }
public int NumeroQuarto { get; set; }
public Nullable<int> NumeroNoites { get; set; }
public Nullable<decimal> Preço { get; set; }
public string Observaçoes { get; set; }
public virtual Cliente Cliente { get; set; }
}
}
I used it, but did not show me the mistakes ... I think the mistake has to do with Id_reserva
– John
u debugged in the line of this code, usually do not print on the console had a similar error to that
– Marcos Brinner
you’d better post the code of your Entity(entity) instead of View
– Marcos Brinner
I made some changes to the code you gave me... now it says the error. You gave me this ---> 'The 'The Type field is required. 'Property does not exist or is not Mapped for the type 'Reserva'.'
– John
Right, half way through but I need you to post your Entity here to see the field, if you’re using the Fluent api, post the Mapping too
– Marcos Brinner
the error says that the Type field is necessary but does not exist or is not being mapped in Entity Reserve, ie it is requesting a value that does not exist, very likely the error is in the relationship of its tables or in its mapping, if you have mapped this field as required you have to provide it at the time of saving the data in the database
– Marcos Brinner
I’ve just edited the question and I’ve already put the entity, what I have in it. As for the maping did not realize what you mean , I started these days in Mvc and I’m still struggling
– John
the mapping that @Marcosbrinner meant is whether the Typoquarto property is configured for Dataannotation or Mapping Fluent API.
– Daniel Nicodemos