I have a list of requests (Vr), in this list I have created a button to end this request (Open Mv)
WhenIclickthisbutton,I'mredirectedtomyLowview,whichhasitsownattributes,plustheRequestId(Vr).Thispartisworkingfine,I'mgettingtheclickonthebutton,andloadingtheselectedobjectinthelowview.Theproblemisin[httpPost],WhenIclicksubmit,therequestidisnull,andthedownidcomeswiththerequestid.
Actionget
publicActionResultMvVr(intid){Vrvrs=newVr();vrs=vrs.BuscarPorIdDaVr(id);Mvmv=newMv();mv.Vrs=vrs;returnView(mv);}
viewofActionOnlyThepartythatloadstherequestdata
@ModelModels.Mv
AboutUs
@using(Html.BeginForm()){@Html.AntiForgeryToken()<divclass="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.Vrs.VrId, "VrId")
<fieldset class="well">
<div class="row">
<div class="col-md-12">
<div class="col-md-4">
<div class="form-group">
@Html.LabelForModel("Motorista", htmlAttributes: new { @class = "" })
@Html.DisplayFor(model => model.Vrs.Motorista.Nome, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
<div class="col-md-4">
<div class="form-group">
@Html.LabelForModel("Usuário", htmlAttributes: new { @class = "" })
@Html.DisplayFor(model => model.Vrs.Usuario.Nome, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
<div class="col-md-4">
<div class="form-group">
@Html.LabelForModel("Itinerario", htmlAttributes: new { @class = "" })
@Html.DisplayFor(model => model.Vrs.Itinerario, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
<div class="col-md-4">
<div class="form-group">
@Html.LabelForModel("VrId", htmlAttributes: new { @class = "" })
@Html.DisplayFor(model => model.Vrs.VrId, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
</div>
</div>
Action HttpPost
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult MvVr(Mv objMv, int VrId)
{
if (ModelState.IsValid)
{
var identity = User.Identity as ClaimsIdentity;
var login = identity.Claims.FirstOrDefault(c => c.Type == "Id").Value;
var usuario = db.UsuariosDb.FirstOrDefault(u => u.Id.ToString() == login);
objMv.IdUsuario = usuario.Id; // Usuário que Finalizou a Vr
//objMv.VrId = VrId;
db.MvDb.Add(objMv);
db.SaveChanges();
TempData["Sucesso"] = "Baixa Realizada Com Sucesso.";
return RedirectToAction("Index", "Painel");
}
TempData["Errado"] = "Favor Preencher os Campos Corretamente.";
return View(objMv);
}