I am basically taking the default ASP.NET MVC template and extending it:
Looking at the site.master, I see this for menus:
<ul id="menu">
<li><%= Html.ActionLink("Home", "Index", "Home")%></li>
<li><%= Html.ActionLink("About", "About", "Home")%></li>
</ul>
I am then editing it by the following:
<ul id="menu">
<li><%= Html.ActionLink("Home", "Index", "Home")%></li>
<li><%= Html.ActionLink("About", "About", "Home")%></li>
<li><%= Html.ActionLink("My Contact Info", "Details/" + Html.Encode(Page.User.Identity.Name), "Users")%></li>
</ul>
The issue is that, in the controller, I have two different methods:
//
// GET: /Users/Details/userName
public ActionResult Details(string loginName)
{
UserInfo user = repo.GetUserByName(loginName);
return View(user);
}
//
// GET: /Users/Details/5
public ActionResult Details(int id)
{
UserInfo user = repo.GetUser(id);
return View(user);
}
I get an exception that says, ambiguous method. Because it can’t figure out which one to call. I would hope that it could figure it out by the data type but apparently not.
Does anyone have any suggestions for supporting details view and querying by different fields? (Of course all of the queryable fields are unique.)
If you had a route like:
which could be used to avoid ambiguity with the default route .. You would need to put this before the default “{controller}/{action}/{id}” route so that it would get priority…
Then, you could have an action like :
You could then access this action like this:
/Users/Details/username or..
/Users/Details?id=userId