2

Passing a param to the controller is null.. from examples ive seen im using correct overload. Any help much appriceated

@{ 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()); } 

browser source code

 <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> 

2 Answers 2

6

You should provide correct parameter name in action link and there is no need to specify parameters here :)

@{ 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> } 
Sign up to request clarification or add additional context in comments.

1 Comment

worked with param name being same, not sure why param names have to match though..
0

If you are using MVC out of the box then it is only likely to work with a parameter called id that accepts an int. To make this work you need to explicitly define the parameter in the URL as below:

<a href="/Customer/Index/?conName=trakman_Entities">trakman_Entities</a> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.