I have a problem with this action:
"activateOffreLocation" checks the value of "Publication_Statut" and change it ( if it equals "Activée", the action change it to "Désactivée" and vice versa
i don't get any error ! it switch simply to the " listOffreLocation" view after asking the confirmation !
i tried to follow the execution with break Points, it turned that in my Post Action the "offreLocation" is null, while the ID is not, it contains the right value of the selected ITEM in the first view.
// GET: /OffreLocation/Activate
public ActionResult ActivateOffreLocation(int id)
{
return View(db.PublicationSet.Find(id));
}
// POST: /OffreLocation/Activate
[HttpPost]
public ActionResult ActivateOffreLocation(int id, OffreLocation offreLocation)
{
try {
var statut = offreLocation.Publication_Statut;
if(String.Equals(statut,"Activée"))
{
offreLocation.Publication_Statut = "Désactivée";
db.SaveChanges();
return View();
}
else
{
offreLocation.Publication_Statut = "Activée";
db.SaveChanges();
return RedirectToAction("ListOffreLocation");
}
}
catch (Exception exp)
{
Console.WriteLine("IOException source: {0}", exp.Source);
return RedirectToAction("Error");
}
}
in my view " listOffreLocation " i just defined the link to the "activateOffreLocation" view:
@Html.ActionLink("Désactiver", "ActivateOffreLocation", new { id = item.Publication_ID }) |
"ActivateOffreLocation" View:
<fieldset style="border:dashed; margin-top:80px">
<h3 style="text-align: center; margin-left:80px; margin-top:80px"> Voullez vous vraiment désactiver cette offre de location?
</h3>
<h4 style="text-align:center"> Num: @Html.EditorFor(model => model.Publication_ID) </h4>
<h4 style="text-align:center"> Statut @Html.EditorFor(model => model.Publication_Statut) </h4>
<div style="margin-bottom:80px">
<hr />
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.HiddenFor(model =>model.Publication_ID)
<div class="form-actions no-color" style="text-align:center">
@Html.HiddenFor(model => model.Publication_ID)
<input type="submit" value="Désactiver" class="btn btn-default" /> |
@Html.ActionLink("Retour à la Liste", "ListOffreLocation")
</div>
}
</div>
</fieldset>