I have passed DIctionary to my view using a viewbag item.
In my view I am them converting back to Dictionary:
var date = veiwbag.Dictionary as Dictionary;
My dcitionary is set up as:
Key = string of date (“MMM yyyy”) eg – SEP 2012
value = int – which is a count of entries in database where the date matches the key.
I am abel to output these Key value pairs. I need to know ho wwhen suer sleects an entry I can return the string Key to an aciton method to retrieve all dates for that string.
I’m new to MVC3 so am a bit lost.
My initial thinking was along the lines of:
(this syntax may be slightly wring as doing from memory)
<a href="(@Href("/Posts/Previous/"+ @date.Key))">@date.key (@date.value)</a>
my controller has action:
public ActionResult Previous(string date)
{
..work on data
return View(..my results);
}
the code in the ActionResult is fine . The link takes me to my ActionResult but the string is null. How do I pass the
date.key
into the ActionResult as a string variable? Am I going about this all the wring way?
You could use a HTML helper to generate a proper link to this controller action:
And if you need to specify the controller name as well you could use the following overload:
Assuming default routes have been setup this will generate the following markup:
and when the Previous controller action is invoked it will successfully be passed the
dateparameter ofSEP 2012.