Reputation: 43
I'm having issues with one of my controller actions .
I have a decimal stored in my viewbag on my view. And am attempting to pass this via and actionlink to my controller method.
ViewBag.Interest =1.25
@Html.ActionLink("Export", "ExportInterest", "Export", new {id = ViewBag.Interest}, null).
My controller method looks something like this :
public ActionResult ExportInterest(decimal? id)
{
return View();
}
I can see the 1.25 be passed via query string but I'm getting a 404 file not found when it's being routed. Note: if I change it to just a whole number with no decimal point it's working fine. Is this an encoding error ? It's not recognising the decimal point , perhaps I need to escape it ? Is there a htmlhelper I should be using? Initially I thought it might be a localisation thing but I have my globalisation culture set up in my web.config. I'm obviously doing something silly here....any help would be appreciated...
Update: I have also tried casting my viewbag to a nullable decimal in the action link but this didn't have any effect
Upvotes: 1
Views: 1007
Reputation: 125
Try that:
decimal? d = (decimal?)ViewBag.Interest;
@Html.ActionLink("Export", "ExportInterest", "Export", new {id = d}, null)
or
@Html.ActionLink("Export", "ExportInterest", "Export", new {id = (decimal?)ViewBag.Interest}, null)
Upvotes: 0
Reputation: 10790
My guess is has to do with the data type in the view bag.
I have passed decimals to controllers before so I know it can be done. But if you changed your link to be:
@Html.ActionLink("Export", "ExportInterest", "Export", new {id =1.25}, null).
Does it work?
Upvotes: 1