2012-08-24 29 views
1

如何在url中传递多个参数从视图到控制器。这是我的网址,而options.parentId是一个参数。我需要传递多个值,我如何传递多个网址中从视图到控制器的值。 ( “/ ProjectRoles/project_module_functions_leftdisplay”,options.parentid)如何在url中传递多个参数

回答

1

您可以使用Url.Action帮手:

@Html.ActionLink(
    "click me", 
    "project_module_functions_leftdisplay", 
    "ProjectRoles", 
    new { 
     parentid = options.parentid, 
     somethingelse = options.somethingelse 
    }, 
    null 
) 

@Url.Action("project_module_functions_leftdisplay", "ProjectRoles", new 
{ 
    parentid = options.parentid, 
    somethingelse = options.somethingelse 
}) 

,或者如果你是一个操作环节中调用控制器

,或者如果您使用的是HTML <form>

@using (Html.BeginForm("project_module_functions_leftdisplay", "ProjectRoles", new { parentid = options.parentid, somethingelse = options.somethingelse })) 
{ 
    ... 
} 

,或者如果我误解你的问题,options是一个javascript变量::

<script type="text/javascript"> 
    var options = ... 
    var url = '@Url.Action("project_module_functions_leftdisplay", "ProjectRoles", new { parentid = "__parentid__", somethingelse = "__somethingelse__" })'; 
    url = url 
     .replace('__parentid__', encodeURIComponent(options.parentid)) 
     .replace('__somethingelse__', encodeURIComponent(options.somethingelse)); 

    // ... use the url here 
</script> 

有可能会成为其他,根据您的具体情况和你想达到什么样的更好的方法。