0

Here's my view code:

@model pedidosOnlineMVC.Models.ViewModel.AdmView
@using pedidosOnlineMVC.Models
@{
    Layout = "~/Views/Administrador/_LayoutAdm.cshtml";
    List<Usuario> lu = pedidosOnlineMVC.Controllers.UsuarioController.favoreds(Model.adm.estabelecimento.Estabelecimento_Id);
}
@using (var f = Html.Bootstrap().Begin(new Form()))
{
    using (var p = Html.Bootstrap().Begin(new Panel())) 
    {
        using (var t = Html.Bootstrap().Begin(new Table())) 
        {
            using (var h = t.BeginHeader()) 
            {
                using(var hr = h.BeginHeaderRow())
                {
                    @hr.Cell("Usuário")
                    @hr.Cell("Status")
                }
            }
            using(var b = t.BeginBody())
            {
                for(int i=0;i<lu.Count;i++)
                {
                    using(var c = b.BeginRow())
                    {
                        @f.FormGroup().CustomControls(Html.HiddenFor(model => model.Usuario_Id[i], lu[i].Usuario_Id))
                        @c.Cell(lu[i].nome)
                        @c.Cell(f.FormGroup().CustomControls(Html.Bootstrap().CheckBoxFor(model=>model.checkAuts[i])))
                    }
                }
            }
        }
        using (var pf = p.BeginFooter())
        {
            @f.FormGroup().CustomControls(@Html.HiddenFor(model => model.adm.Administrador_Id, Model.adm.Administrador_Id))
            @f.FormGroup().CustomControls(Html.Bootstrap().SubmitButton().Text("Autorizar"))
        }
    }
}

And I had a similar problem here: cshtml page not passing date value on post, but what I did then doesn't work here. I tried looking in the network window in the developer tools and I can see the ID values (Administrador_ID and Usuario_ID) being sent on post, but they never reach my controller. Here's the code for the controller:

[HttpPost]
public ActionResult autCli(AdmView adm)
{
    return null;
}

It has no code in it because I still didn't get it to work, but the parameters should still work when debugging, but I get NULL in every attribute instead. If anyone can help, I'd appreciate it.

AdmView model, as requested:

public class AdmView
{
    public Administrador adm { get; set; }
    public Produto prod { get; set; }
    public virtual List<bool> checkAuts { get; set; }
    public virtual List<int> Usuario_Id { get; set; }
}
Community
  • 1
  • 1

2 Answers2

0

Add [HttpPost] before your ActionResult method.

javisrk
  • 582
  • 4
  • 19
0

Try to use the FormCollection to pass data from view to controller.

Just like this:

[HttpPost]
public ActionResult autCli(FormCollection collection)
{
  strint Usuario_Id = collection["Usuario_Id"]; //You can get data with this way...
  return View();
}

Check this question for more info.

Community
  • 1
  • 1
Uğur Aldanmaz
  • 1,018
  • 1
  • 11
  • 16