mardi 31 mars 2015

Action link with string id returning HTTP Error 404.0 - Not Found..

I would like to receive a string as the id passed from action link in a view. But for some reason I always get the error HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. When I was debugging the delete code in the controller never gets executed it just throws an error. I do not understand why I cannot achieve it with the following code.



//action link passing id (string)

<td>
@Html.ActionLink("Delete Room", "Delete", new {id=item.RoomName})|

</td>



//controller method Delete
public ActionResult Delete(string id)
{
Room room = db.Rooms.Find(id);
if (room == null)
{
return HttpNotFound();

}
return View(room);
}



//RouteConfig.cs
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}

Aucun commentaire:

Enregistrer un commentaire