Can’t understand where the problem… My rout values is :
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
And i try to pass parameter id :
@Html.ActionLink(app.Name, "SingleAppEdit", "Admin", new { id = app.Id }, null)
To my action in Controller “Admin”:
public ActionResult SingleAppEdit(string appId)
{
var positions = new List<SelectListItem>
{
new SelectListItem() {Text = "Top", Value = "Top"},
new SelectListItem() {Text = "Bottom", Value = "Bottom"},
new SelectListItem() {Text = "None", Value = "None"}
};
ViewData["PositionsList"] = new SelectList(positions, "Value", "Text");
var app = Apps.FirstOrDefault(a => a.Id == Convert.ToInt32(appId));
return View(app);
}
I get null in controller. Can anybody help?
Your method parameter name is
appId. But you are trying to pass a parameter namedid.Solution : Change your parameter name to match with the method definition.