Laziale
Laziale

Reputation: 8225

pass parameter in mvc4 partial view

I created a partial view with google code and I want to send two parameters to that view. Here is the content for the partial view:

    <!-- Google Code for apply Conversion Page --> <script type="text/javascript">
   /* <![CDATA[ */
   var google_conversion_id = 1234567;
   var google_conversion_language = "en";
   var google_conversion_format = "2";
   var google_conversion_color = "ffffff";
   var google_conversion_label = "7df7df7sdfdf"; var google_conversion_value = 0;
   /* ]]> */
   </script>
   <script type="text/javascript"  
   src="https://www.googleadservices.com/pagead/conversion.js">
   </script>
   <noscript>
   <div style="display:inline;">
   <img height="1" width="1" style="border-style:none;" alt=""  
   src="https://www.googleadservices.com/pagead/conversion/1234567/?value=0&amp;label=7df7df7sdfdf&amp;guid=ON&amp;script=0"/>
   </div>
   </noscript>

Now instead of the static value for google_conversion_id and google_conversion_label I want to use two parameters which I'll sent from the main form.

Here is how I call the partial view:

@{ Html.RenderPartial("Google"); }

Any idea how can I achieve that? Thx, Laziale

Upvotes: 1

Views: 2733

Answers (1)

slfan
slfan

Reputation: 9129

You could use RenderAction instead of RenderPartial. Then you can write you own action in the controller and you can add parameters. Something like this:

@{ Html.RenderAction("Action", "Controller", new { id = "Something", label = "Label" }); }

or you create a new model for the partial view in the code behind.

Another option would be to store the parameters in the ViewBag, but that's more like a hack.

Upvotes: 1

Related Questions