简体   繁体   English

在mvc4部分视图中传递参数

[英]pass parameter in mvc4 partial view

I created a partial view with google code and I want to send two parameters to that view. 我用Google代码创建了部分视图,我想向该视图发送两个参数。 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. 现在,我要使用从主表单发送的两个参数,而不是google_conversion_id和google_conversion_label的静态值。

Here is how I call the partial view: 这就是我所说的局部视图:

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

Any idea how can I achieve that? 知道如何实现吗? Thx, Laziale Laziale Thx

You could use RenderAction instead of RenderPartial. 您可以使用RenderAction代替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. 另一个选择是将参数存储在ViewBag中,但这更像是黑客。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM