3
I have a page that performs maintaining 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 view heavily typed with Orcamento
@model HT.Dominio.Entidade.Orcamento
And the fields of OrcamentoItem
and Historico
I put in hand, that is, without the use of Html.Helpers
.
With this I lose the validations that MVC already creates for me when using the Helper ValidationMessageFor
, among other problems also.
To save I’m doing everything via Ajax, filling everything in hand, a damned 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?
Split into Forms in view for each entity and sends through submit
, or create in partialview and call each one in his place? Or leave everything as it is and go away?
Thank you, guys!
Why you don’t use the Helpers in HTML?
– Leonel Sanches da Silva
Ola Cigano, I think more for lack of experience with MVC. Now reading some articles I’m thinking of separating everything in Partialview.
– Henrique Abreu
Yes, it is correct. By the way, MVC is already prepared for Ajax. You just need to learn how to use the extensions.
– Leonel Sanches da Silva