Answered by:
MVC

Question
-
I have a problem in my MVC application. I'm novice in MVC programming.
I have a post form, but it doesn't get the informations of the form.
I need to get a id from the form and pass it to the controller, but it isn't working.
Someone help me.
My form code:(Ps.: I'm brazilian)
@{ ViewBag.Title = "Excluir"; } @model UI.Models.Carro @using (Html.BeginForm("Excluir","Carro",FormMethod.Post)) { <h2>Excluir</h2> <h3>Are you sure you want to delete this?</h3> <fieldset> <legend>Carro</legend> <div class="display-label"> @Html.DisplayNameFor(model => model.IdCarro) </div> <div class="display-field"> @Html.DisplayFor(model => model.IdCarro) </div> <div class="display-label"> @Html.DisplayNameFor(model => model.nomCarro) </div> <div class="display-field"> @Html.DisplayFor(model => model.nomCarro) </div> <div class="display-label"> @Html.DisplayNameFor(model => model.marCarro) </div> <div class="display-field"> @Html.DisplayFor(model => model.marCarro) </div> <div class="display-label"> @Html.DisplayNameFor(model => model.anoCarro) </div> <div class="display-field"> @Html.DisplayFor(model => model.anoCarro) </div> <div class="display-label"> @Html.DisplayNameFor(model => model.quantCaro) </div> <div class="display-field"> @Html.DisplayFor(model => model.quantCaro) </div> <div class="display-label"> @Html.DisplayNameFor(model => model.precoCar) </div> <div class="display-field"> @Html.DisplayFor(model => model.precoCar) </div> </fieldset> @Html.AntiForgeryToken() <p> <input type="submit" value="Excluir" /> | @Html.ActionLink("Back to List", "Index") </p> }
And my controller:
[HttpPost] public ActionResult Excluir(Carro carro) { int id = carro.IdCarro; DaoCarrocs dao = new DaoCarrocs(); dao.delete(id); return RedirectToAction("Index"); }
Someone help me. My early thanks.
- Moved by Grady_Dong Friday, December 4, 2015 1:38 AM Off-Topic
Thursday, December 3, 2015 5:30 PM
Answers
-
You are posting to the WCF forum.
You need to post to the ASP.NET MVC forum.
- Proposed as answer by Dave PatrickMVP Friday, December 4, 2015 1:42 AM
- Marked as answer by Just Karl Friday, December 11, 2015 11:27 PM
Thursday, December 3, 2015 9:38 PM -
Hi Guilherme Romão,
Thanks for your post!
This forum is to discuss problems of WCF. Your question is not related to the topic of this forum.
If the MVC means the ASP.NET MVC, I suggest that you could post it in the ASP.NET MVC forum
for efficient response.
There is a link may benefit you:
Best Regards,
Grady
- Proposed as answer by Dave PatrickMVP Friday, December 4, 2015 1:42 AM
- Marked as answer by Just Karl Friday, December 11, 2015 11:27 PM
Friday, December 4, 2015 1:37 AM
All replies
-
Hi, this article tacle Post forms using asp mvc with razor.
http://blog.michaelckennedy.net/2012/01/20/building-asp-net-mvc-forms-with-razor/
Regards.
Mohamed Ali BEN HAMIDA.
Please remember to mark your question as "answered"/"Vote helpful" if this solves/helps your problem
Thursday, December 3, 2015 5:41 PM -
You are posting to the WCF forum.
You need to post to the ASP.NET MVC forum.
- Proposed as answer by Dave PatrickMVP Friday, December 4, 2015 1:42 AM
- Marked as answer by Just Karl Friday, December 11, 2015 11:27 PM
Thursday, December 3, 2015 9:38 PM -
Hi Guilherme Romão,
Thanks for your post!
This forum is to discuss problems of WCF. Your question is not related to the topic of this forum.
If the MVC means the ASP.NET MVC, I suggest that you could post it in the ASP.NET MVC forum
for efficient response.
There is a link may benefit you:
Best Regards,
Grady
- Proposed as answer by Dave PatrickMVP Friday, December 4, 2015 1:42 AM
- Marked as answer by Just Karl Friday, December 11, 2015 11:27 PM
Friday, December 4, 2015 1:37 AM