gpt4 book ai didi

asp.net-mvc-3 - 在部分 View 中获取 viewdatadictionary 值

转载 作者:行者123 更新时间:2023-12-02 05:10:12 26 4
gpt4 key购买 nike

我有一个部分 View ,我试图从父 View 中获取值。这就是我正在尝试的:

 @Html.Partial("Shared", "Home", new ViewDataDictionary { { "9595959", "8sd8sds8das8d" } }) 

这是部分 View :

      <!-- Google Code for apply Conversion Page --> <script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = "viewdata-number1";
var google_conversion_language = "en";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "viewdata-number2"; 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/viewdata-number1/?value=0&amp;label=viewdata-number2&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

是否可以立即获取该值?我没有分配给部分 View 的任何模型或 Controller 。提前致谢,Laziale

更新的代码:

@{
var variable = ViewData["First"];
<!-- Google Code for apply Conversion Page --> <script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = variable;
var google_conversion_language = "en";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "f6vICKTT6gMQzNOf3gM"; 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/1002957260/?value=0&amp;label=f6vICKTT6gMQzNOf3gM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>
}

你认为这会起作用吗?

最佳答案

抱歉,我不太明白你的问题。您可以像这样获取部分 ViewData 值:

var a = (int)ViewData["9595959"]; // variable a will get value "8sd8sds8das8d"

您还可以创建新的 ViewDataDictionary 来扩展当前 View ViewDataDictionary,如下所示:

 @Html.Partial("Shared", "Home", new ViewDataDictionary(ViewData) { { "9595959", "8sd8sds8das8d" } }) 

它将像这样工作:

 @{
var variable = (int)ViewData["First"];
}
<!-- Google Code for apply Conversion Page --> <script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = @variable;
var google_conversion_language = "en";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "f6vICKTT6gMQzNOf3gM"; 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/1002957260/?value=0&amp;label=f6vICKTT6gMQzNOf3gM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

关于asp.net-mvc-3 - 在部分 View 中获取 viewdatadictionary 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13709631/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com