Click here to Skip to main content
15,850,548 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,I am using asp.net MVC3.In my controller I have an action method like:
SQL
public ActionResult ListView(int id)
        {
           ViewBag.key = id;
            return View();
        }


In the view, how To pass this value dynamically in the url
I passed in the url like:
"/Home/GetDetails/id = " + '@ViewBag.key'
can i pass the id in this way?
I am getting an error like"The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method system.web.MVC.ActionRestult... ",can u tell me any other way to pass this id dynamically to the url.
Posted
Updated 6-Jul-12 3:08am
v2
Comments
Raghuveer Kasyap 6-Jul-12 7:58am    
[HttpPost] attribute shoould be used

1 solution

You need to convert the value to a string. Try :
@{= Convert.ToString(ViewBag.key) }


Although it would be better to create a helper method.

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900