Giorgos Manoltzas
Giorgos Manoltzas

Reputation: 1718

Pass javascript parameter to partial view in asp.net mvc

lets say I want to a partial view like the following sample

@Html.RenderAction("ListDocuments", "MultiFileAttachments", new { id = jsparameter }); 

in the jsparameter I want to pass as a parameter that is the result of a javascript function. Maybe this is not logical because javascript runs on the client, but how can I achieve a similar functionality ? thank you in advance

Upvotes: 2

Views: 2519

Answers (1)

Yan Brunet
Yan Brunet

Reputation: 4897

If you need to call a part of a page based on some actions or values determined by actions on the client side, then you should think to use JavaScript (preferably jQuery) and Ajax.

Through jQuery-Ajax, you could easily call a Partial view through the Contoler and since it's a regular HTTP request, you would be able to pass all the parameters you need.

Using code as :

@Html.RenderAction("ListDocuments", "MultiFileAttachments", new { id = jsparameter });

is not possible since it is rendered by the server before it's sent to the client browser.

Upvotes: 1

Related Questions