Reputation: 5002
I have created a new .cshtml file. URL of this view is: mypage?id=1
When I want to get value of id
in URL with using Request.Params["id"]
it doesn't return any value.
Actually Request
object isn't seen on this view. I use it in another page it works fine. I don't understand why Request
isn't available on new page.
Upvotes: 0
Views: 32
Reputation: 8521
Its not really a good design to access querystring parameters in a view. I would recommend putting id into a View Model and accessing it from there. Or another option would be passing the value of id into the view using the ViewBag, for example:
Controller
Public ActionResult MyPage(int id)
{
ViewBag.Id = id;
return View();
}
View
<Some Code....>
<div>
@ViewBag.Id
</div>
</Some Code....>
Upvotes: 2