How to pass a variable through url and use it inside a controller
Posted
by
anthonypliu
on Stack Overflow
See other posts from Stack Overflow
or by anthonypliu
Published on 2011-03-17T00:07:12Z
Indexed on
2011/03/17
0:09 UTC
Read the original article
Hit count: 168
I have this controller:
public ActionResult Details(String UserName)
{
using (var db = new MatchGamingEntities())
{
var Users = from m in db.Users
join m2 in db.MyProfiles on m.UserId equals m2.UserId
where m.UserName == UserName
select new UserViewModel
{
UserName = m.UserName,
LastActivityDate = m.LastActivityDate,
Address = m2.Address,
City = m2.City,
State = m2.State,
Zip = m2.Zip
};
return View(Users.SingleOrDefault());
}
}
I type in the url Profiles/Details/hello, but it does not work, if I do Profiles/Details?UserName=hello then it works. I have another ActionResult just like this except taking in an int id as parameter and it works fine with the first url format.
© Stack Overflow or respective owner