HTML.ActionLink方法中的路由参数值是什么?它的语法是什么?
在微软网站上:我发现了HTML.ActionLink方法中的路由参数值是什么?它的语法是什么?,html,asp.net-mvc-4,actionlink,Html,Asp.net Mvc 4,Actionlink,在微软网站上:我发现了HTML.ActionLink的用法。作者描述了它的参数。在第三点中,他指的是路线参数值。看起来像是在创建新对象。我一点也不明白第一个参数已经描述了名称。我们为什么需要第三个参数? 链接文本,将显示流派名称 控制器操作名称(浏览) 路由参数值,指定名称(流派)和值(流派名称) 问题:HTML.ActionLink中的路由参数值是什么,ti的正确语法是什么 课程类型: using System; using System.Collections.Generic; usin
HTML.ActionLink
的用法。作者描述了它的参数。在第三点中,他指的是路线参数值。看起来像是在创建新对象。我一点也不明白第一个参数已经描述了名称
。我们为什么需要第三个参数?
课程类型:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcMusicStore.Models {
public class Genre {
public string Name { get; set; }
}
}
Route参数传递给操作请求的查询字符串。在控制器操作中,您会看到方法签名是Browse(stringgenre),这意味着名为genre的参数是必需的。action link的第三个参数就是这样做的——它添加了一个参数流派,其值被指定给对象流派的属性名称 ActionLink参数映射如下:
@Html.ActionLink(
genre.Name, // display of the link in a tag
"Browse", // name of the action, it redirects to public ActionResult Browse(string genre)
new {
genre = //name of the parameter for the controller action Browse(string **genre**)
genre.Name // value of the parameter
})
Route参数传递给操作请求的查询字符串。在控制器操作中,您会看到方法签名是Browse(stringgenre),这意味着名为genre的参数是必需的。action link的第三个参数就是这样做的——它添加了一个参数流派,其值被指定给对象流派的属性名称 ActionLink参数映射如下:
@Html.ActionLink(
genre.Name, // display of the link in a tag
"Browse", // name of the action, it redirects to public ActionResult Browse(string genre)
new {
genre = //name of the parameter for the controller action Browse(string **genre**)
genre.Name // value of the parameter
})
第一个参数是显示名称,第二个参数是动作名称,第三个参数实际上是控制器动作的参数,例如:
@Html.ActionLink("LinkText",
"Browse",
new { parameter1 = "1",parameter2 = "2" })
现在,您的操作将如下所示:
public ActionResult Browse(string parameter1,string parameter2)
{
}
它有许多可用的重载
请参见第一个参数是显示名称,第二个参数是动作名称,第三个参数实际上是控制器动作的参数,例如:
@Html.ActionLink("LinkText",
"Browse",
new { parameter1 = "1",parameter2 = "2" })
现在,您的操作将如下所示:
public ActionResult Browse(string parameter1,string parameter2)
{
}
它有许多可用的重载
看