I have a page that maintains a budget.
Below I present a briefing of entities
public partial class Orcamento
{
public int IdPedidoCompra { get; set; }
public int IdCliente { get; set; }
public System.DateTime DataPedido { get; set; }
public decimal Valor { get; set; }
}
public partial class OrcamentoItem
{
public int IdOrcamentoItem { get; set; }
public int IdOrcamento { get; set; }
public int IdProduto { get; set; }
public int Quantidade { get; set; }
public decimal PrecoUnitario { get; set; }
}
public partial class Historico
{
public int IdHistorico { get; set; }
public Nullable<int> IdOrcamento { get; set; }
public string NomeContato { get; set; }
public System.DateTime DataContato { get; set; }
public string Observacao { get; set; }
public Nullable<System.DateTime> DataProximoContato { get; set; }
}
Based on these tables I created my strongly typed view with Orcamento
@model HT.Dominio.Entidade.Orcamento
And the fields of OrcamentoItem
and Historico
I put in the hand, that is, without using Html.Helpers
.
With this I lose the validations that MVC already creates for me when using Helper ValidationMessageFor
, among other problems as well.
To save I'm doing everything via Ajax, filling everything in hand, a damn job.
//cria o objeto json
var orcamento = {"campo1", "campo2"....}
var orcamentoitens = {"campo1", "campo2"....}
//preenche o objeto
//envia ao servidor
$.ajax({
type: "POST",
url: "/Orcamento/Salvar/",
data: JSON.stringify(orcamento),
contentType: 'application/json;',
datatype: "json",
success: function (retorno) {}
});
So I ask, what's the right way to do this?
Separate in forms in view for each entity and send via submit
, or create in partialview and call each in your place? Or do I leave everything as is and leave?
Thanks, guys!