MVC3 构建输入连接的方法

1.Html.ActionLink();

@Html.ActionLink("About this application", "About") //产生连接到同一controller的Action方法

@Html.ActionLink("About this application", "About", "MyController") //产生连接到另一个controller的方法。

//带入其他参数

@Html.ActionLink("About this application", "About", "MyController",new {id="MyID"});

//当传递的参数多于Route需要的参数时,将被转化成查询字符串,例如:

@Html.ActionLink("About this application", "About",
new { id = "MyID", myVariable = "MyValue" })

产生的连接为:

<a href="/Home/About/MyID?myVariable=MyValue">About this application</a>

//指定HTML属性

@Html.ActionLink("About this application", "Index", "Home", null,
new {id = "myAnchorID", @class = "myCSSClass"})

产生的链接为:

<a class="myCSSClass" href="/" id="myAnchorID">About this application</a>

你可能感兴趣的:(mvc)