У меня есть приложение MVC 3 с сущностью.Я потерял свои данные на submit MVC 3
На моей странице я использую пользовательскую модель, содержащую все объекты, которые я использую. Страница отображается отлично, но когда я нажимаю кнопку отправки, мой объект теряет данные.
Это мой заказ модель:
public class ControleAcessoModel
{
private List<Controle> controles = new List<Controle>();
public GRUPO_ACESSO_TB grupo_acesso_tb { get; set; }
public List<Controle> Controles
{
get
{
return controles;
}
}
public void AddTela(byte id, string nome)
{
Controle ctrl = new Controle();
ctrl.ID_TELA = id;
ctrl.NM_TELA = nome;
controles.Add(ctrl);
}
public class Controle
{
public bool Selecionado { get; set; }
public byte ID_TELA { get; set; }
public string NM_TELA { get; set; }
public bool FL_SALVAR { get; set; }
public bool FL_ALTERAR { get; set; }
public bool FL_EXCLUIR { get; set; }
}
}
это мой Razor Html код:
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<table>
<tr>
<th>Salvar</th>
<th>Editar</th>
<th>Excluir</th>
<th>Tela</th>
</tr>
@foreach (var item in Model.Controles)
{
<tr>
<td style="text-align: center">
@Html.EditorFor(modelItem => item.FL_SALVAR)
</td>
<td style="text-align: center">
@Html.EditorFor(modelItem => item.FL_ALTERAR)
</td>
<td style="text-align: center">
@Html.EditorFor(modelItem => item.FL_EXCLUIR)
</td>
<td>
@Html.DisplayFor(modelItem => item.NM_TELA)
</td>
</tr>
}
</table>
<p>
<input type="submit" value="Salvar" />
</p>
}
Это мой создать код, где я помещал данные по базе данных. Является ли в этой части, что мой объект controleacessomodel пуст.
[HttpPost]
public ActionResult Create(ControleAcessoModel controleacessomodel, byte id)
{
if (ModelState.IsValid)
{
for (int i = 0; i < controleacessomodel.Controles.Count; i++)
{
if (ValidaSelecao(controleacessomodel.Controles[i]))
{
PERMISSAO_GRUPO_ACESSO_TELA_TB permissao = new PERMISSAO_GRUPO_ACESSO_TELA_TB();
permissao.ID_GRUPO_ACESSO = controleacessomodel.grupo_acesso_tb.ID_GRUPO_ACESSO;
permissao.ID_TELA = controleacessomodel.Controles[i].ID_TELA;
permissao.FL_SALVAR = controleacessomodel.Controles[i].FL_SALVAR;
permissao.FL_ALTERAR = controleacessomodel.Controles[i].FL_ALTERAR;
permissao.FL_EXCLUIR = controleacessomodel.Controles[i].FL_EXCLUIR;
db.PERMISSAO_GRUPO_ACESSO_TELA_TB.AddObject(permissao);
}
}
db.SaveChanges();
return RedirectToAction("Edit", "GrupoAcesso", new { id = id });
}
return View(controleacessomodel);
}
Почему мой объект пуст после отправки?
У вас есть форма на ваш взгляд? – pollirrata
Да, у меня есть форма! –