Entity Framework & ASP.NET MVC: can't get to the [HttpPost] on my controller from another one

Multi tool use
Entity Framework & ASP.NET MVC: can't get to the [HttpPost] on my controller from another one
I'm trying to redirect the user from this view on the SolicitantesController
to the one on the Create
of ExpedientesController
:
SolicitantesController
Create
ExpedientesController
@model Entrega02Programacion03.Models.Solicitante
@{
ViewBag.Title = "InformeSolicitante";
}
<h2>InformeSolicitante</h2>
<div>
<h4>Solicitante</h4>
<hr />
<dl class="dl-horizontal">
<dd>Cedula: @ViewBag.Cedula </dd>
<dd> Nombre: @ViewBag.Nombre</dd>
<dd>Apellido: @ViewBag.Apellido</dd>
<dd>Email: @ViewBag.Email</dd>
<dd>Tel: @ViewBag.tel</dd>
</dl>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Crear Expediente" class="btn btn-default" />
</div>
</div>
</div>
This is the post on solicitantesController
, but I can't get my button Crear Expediente
to get there, any ideas of what I may be doing wrong? Thanks
solicitantesController
Crear Expediente
[HttpPost]
public ActionResult InformeSolicitantes()
{
return RedirectToAction("Expedientes", "Create");
}
The is no point having a submit button without the form. But you are not editing anything, nor changing data in the POST method, so neither a form or submit button is appropriate. Just use a link and redirect to your
Create()
method in ExpedientesController
– Stephen Muecke
Jul 1 at 3:58
Create()
ExpedientesController
tks, what I ended up doing was just having a function that redirect to the appropriate controller , and I call that function on the button on the view
– neoMetalero
Jul 1 at 5:24
1 Answer
1
i suggest two solutions to solve it:
1)replace submit html control with anchor link with InformeSolicitantes action url and remove [HttpPost]
for example replace
<input type="submit" value="Crear Expediente" class="btn btn-default" />
with
<a class="btn btn-default" href="action path/name"></a>
then remove
[HttpPost]
[HttpPost]
2)put input control into form control and set form action and controllers to hit InformeSolicitantes action.
for example replace
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Crear Expediente" class="btn btn-default" />
</div>
</div>
with
<form action="action path/name" method="post"><div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Crear Expediente" class="btn btn-default" />
</div>
</div></form>
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Try putting it inside a <form> tag then set the action to InformeSolicitantes
– Redan
Jul 1 at 2:32