I'm new to MVC2 and was wondering if it was possible to pass an object into a Controller Action from a View?
e.g. I've created a ViewModel containing a list of DirectoryInfo objects and pass this to my Index view.
In the view, I loop through all of the DI objects and for each one create an ActionL开发者_运维问答ink.
<%:Html.ActionLink(linkText: subfolder.Name,actionName: "Reports",
routeValues: new {folder=subfolder}, htmlAttributes:null )%>
but in my Reports action, the "folder" is always null?
public ActionResult Reports(DirectoryInfo folder)
{
//folder is always null here
Is this type of thing possible, or does the routingValue always have to be a primitive?
(ps. I have searched StackOverflow and t'internet and although I can find people asking the same question, I can't find a solution
DirectoryInfo
is a complex object and I don't think you will be able to put it directly into HTML. You need to send something simple like path of directory or file from which controller can construct the required DirectoryInfo
again.
精彩评论