Reputation: 664
how to pass multiple parameters from view to the controller in the url.This is my url,and options.parentId is one parameter.I need to pass multiple values ,how can i pass multiple values from view to controller in the url. ("/ProjectRoles/project_module_functions_leftdisplay", options.parentid)
Upvotes: 1
Views: 1303
Reputation: 1039050
You could use the Url.Action helper:
@Url.Action("project_module_functions_leftdisplay", "ProjectRoles", new
{
parentid = options.parentid,
somethingelse = options.somethingelse
})
or if you are calling the controller within an action link:
@Html.ActionLink(
"click me",
"project_module_functions_leftdisplay",
"ProjectRoles",
new {
parentid = options.parentid,
somethingelse = options.somethingelse
},
null
)
or if you are using an HTML <form>
:
@using (Html.BeginForm("project_module_functions_leftdisplay", "ProjectRoles", new { parentid = options.parentid, somethingelse = options.somethingelse }))
{
...
}
or if I misunderstood your question and options
is a javascript variable::
<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>
There might as well be other, better approaches depending on your exact scenario and what you are trying to achieve.
Upvotes: 1