将参数传递给控制器是空的。从我看到的示例中,我使用了正确的重载。任何帮助都非常感激
@{
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>
}
}
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());
}
浏览器源代码
<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>