Jed*_*d I 2 c# asp.net-mvc actionresult
将一个参数传递给控制器是空的..从我看到的使用正确的重载的例子.任何有用的帮助
@{
foreach (string str in ViewBag.ServerNames)
{
<ul>
<img src="../../Content/Images/my_computer.png" alt="Computer Name"/>
<li >@Html.ActionLink(linkText: str.ToString(),actionName: "Index",controllerName:"Customer",
routeValues:new{str = str.ToString()} , htmlAttributes: null)</li>
</ul>
}
Run Code Online (Sandbox Code Playgroud)
}
public ActionResult Index(string conName)
{
Response.Write("con name = " + conName);
Response.End();
string con = ConfigurationManager.ConnectionStrings[conName].ConnectionString;
trakman_Entities db = new trakman_Entities(con);
return View(db.customers.ToList());
}
Run Code Online (Sandbox Code Playgroud)
浏览器源代码
<ul>
<img src="../../Content/Images/my_computer.png" alt="Computer Name"/>
<li ><a href="/Customer/Index/DefaultConnection">DefaultConnection</a></li>
</ul>
<ul>
<img src="../../Content/Images/my_computer.png" alt="Computer Name"/>
<li ><a href="/Customer/Index/trakman_Entities">trakman_Entities</a></li>
</ul>
<ul>
<img src="../../Content/Images/my_computer.png" alt="Computer Name"/>
<li ><a href="/Customer/Index/trakman_Entities1">trakman_Entities1</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
您应该在操作链接中提供正确的参数名称,这里不需要指定参数:)
@{
foreach (string str in ViewBag.ServerNames)
{
<ul>
<img src="../../Content/Images/my_computer.png" alt="Computer Name"/>
<li >@Html.ActionLink(str.ToString(),"Index","Customer",
new{conName= str.ToString()} , null)</li>
</ul>
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7425 次 |
| 最近记录: |