Измените маршрут по умолчанию в вашем global.asax.cs на -
routes.MapRoute(
"Default", // Route name
"{controller}/{id}/{action}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
Создайте UserController с помощью метода Show, подобного этому -
public class UserController : Controller
{
public ActionResult Show(int id)
{
var model = new UserViewModel {Id = id};
// Retrieve user from data layer and update model with other user details here
return View(model);
}
public ActionResult Edit(int id)
{
// Deal with edit action in here
}
}
public class UserViewModel
{
public int Id { get; set; }
}
В представлении aspx убедитесь, что ваша страница наследуется от ViewPage<UserViewModel>
, объявив в директиве страницы вашего представления aspx -
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<UserViewModel>" %>
Затем вы можете создать ссылку для редактирования на своей странице следующим образом -
<%=Html.ActionLink("Edit User", "Edit", new { id = Model.Id }) %>