I posted last week that chrome kept giving me http 500 errors in a partial view. So I made it a regular view and I got the error in all the browsers. I come to learn, I was not passing the ID correctly for details view. I am trying to pass an ID to the
layout and have it pull the data if it exists. This works in all localhost environments again but not live. I am getting 500 server errors . I think the ID still isnt passing correctly.
The detail view is a scaffolded view nothing to cause the problem
I think the problem is in my controller code or action link
Controller Code
[HttpGet]
public ActionResult UserPanel(string id)
{
RatingModel newrating = new RatingModel();
//if(id != null)
if (Request.Cookies["UserInfo"] != null) // Checks for User Cookie
{
System.Collections.Specialized.NameValueCollection UserInfoCookieCollection;
UserInfoCookieCollection = Request.Cookies["UserInfo"].Values;
newrating.ScreenName = Server.HtmlEncode(UserInfoCookieCollection["ScreenName"]);
id = Server.HtmlEncode(UserInfoCookieCollection["UserId"]); // ID is here
// id = newrating.Userid;
var UserTableModel = (from c in db.Users
where c.UserId == id//UserId //newrating.Userid
select c).Single();
return View(UserTableModel);
}
else
{
return View("UserPanelBlank");
}
//return PartialView("UserPanelBlank");
}
And the Actionlink on the menu
@Html.ActionLink("User Panel", "UserPanel", new { id = @Html.Encode(Request["id"]) }, new { @id = "userOn" })
I think might have something to do with the routing in the action, any ideas?
mbhahn
Member
169 Points
119 Posts
Passing Id for Detail Views
May 14, 2012 08:20 PM|LINK
I posted last week that chrome kept giving me http 500 errors in a partial view. So I made it a regular view and I got the error in all the browsers. I come to learn, I was not passing the ID correctly for details view. I am trying to pass an ID to the layout and have it pull the data if it exists. This works in all localhost environments again but not live. I am getting 500 server errors . I think the ID still isnt passing correctly.
The detail view is a scaffolded view nothing to cause the problem
I think the problem is in my controller code or action link
Controller Code
[HttpGet] public ActionResult UserPanel(string id) { RatingModel newrating = new RatingModel(); //if(id != null) if (Request.Cookies["UserInfo"] != null) // Checks for User Cookie { System.Collections.Specialized.NameValueCollection UserInfoCookieCollection; UserInfoCookieCollection = Request.Cookies["UserInfo"].Values; newrating.ScreenName = Server.HtmlEncode(UserInfoCookieCollection["ScreenName"]); id = Server.HtmlEncode(UserInfoCookieCollection["UserId"]); // ID is here // id = newrating.Userid; var UserTableModel = (from c in db.Users where c.UserId == id//UserId //newrating.Userid select c).Single(); return View(UserTableModel); } else { return View("UserPanelBlank"); } //return PartialView("UserPanelBlank"); }And the Actionlink on the menu
ignatandrei
All-Star
135023 Points
21648 Posts
Moderator
MVP
Re: Passing Id for Detail Views
May 14, 2012 08:55 PM|LINK
What is the URL that gives you 500 ?
What's the controller name?
mbhahn
Member
169 Points
119 Posts
Re: Passing Id for Detail Views
May 14, 2012 09:09 PM|LINK
The Controller Name is UserPanel /// HOME Controller I meant UserPanel Action
Its not passing the ID in the URL,
I added this route in the global asax, it works on local manually but its not pushing the url over when its clicked.
i got the below code from Stephen Walters example.
routes.MapRoute( name: "UserPanel/{id}", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "UserPanel", id = @"\d+" }I have 1 controller for all my logic for the entire application so far too.
/home/UserData/ has the error url but works local host
it should be /Home/UserData/ID
ignatandrei
All-Star
135023 Points
21648 Posts
Moderator
MVP
Re: Passing Id for Detail Views
May 14, 2012 09:44 PM|LINK
1
I hope that is UserPanelController
2.
I hope that the action is not UserPanel again
3.
I do not understand how MVC will generate USERDATA from
mbhahn
Member
169 Points
119 Posts
Re: Passing Id for Detail Views
May 14, 2012 10:49 PM|LINK
I goofed up
Its the Home Controller and UserPanel is the Action on that Controller.
I am using just the home controller. Sorry.
I just want it to display. I dont care if it shows in the url or not .
mbhahn
Member
169 Points
119 Posts
Re: Passing Id for Detail Views
May 14, 2012 11:17 PM|LINK
I just uploaded a build with those route values, its working on all browsers but it isnt showing the id but ok
I sent you a PM to the site
Ty ignatandrei
ignatandrei
All-Star
135023 Points
21648 Posts
Moderator
MVP
Re: Passing Id for Detail Views
May 15, 2012 06:31 AM|LINK
nice.