参考:http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/examining-the-edit-methods-and-edit-view

本文内容:

1,熟悉MVC的路由过程,URL如果导向到Controller相应的方法中

2,新增SearchIndex页面,实现简单的查询功能

 

http://localhost:9898/Movies鼠标移动到”Edit”上面的时候,我们看到Edit将要导向的路径

ASP.NET MVC 学习4、Controller中添加SearchIndex页面,实现简单的查询功能

这个路径对应的HTML代码是: @Html.ActionLink("Edit", "Edit", new { id = item.ID })

参数说明:第一个参数linkText链接文字,第二个参数是需要调用的action 方法,第三个参数是匿名对象(anonymous object)生成路由数据:

ASP.NET MVC 学习4、Controller中添加SearchIndex页面,实现简单的查询功能

HTML对象的ActionLink method 动态生成(dynamically genetate)HTML链接指向Controller中的 action methods.

 http://localhost:9898/movies/Edit/1 这个url路径,asp.net会根据MVC中默认的路由配置(App_Start\RouteConfig.cs)按照{controller}/{action}/{id}的格式进行导向:{movies}/{Edit}/{1}    默认路由配置:

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 }
);
}
}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2021-09-23
猜你喜欢
  • 2021-05-21
  • 2022-12-23
  • 2023-01-29
  • 2021-12-25
  • 2022-12-23
相关资源
相似解决方案