我有这样的代码:
<div id="SettingsTabPanel" class="tabbable-line" style="padding-top:20px;">
<div id="ProjectTimeLine" class="tab-pane">
@{ var test = 10;}
@test
</div>
@Html.Partial("~/Views/PortfolioResearch/Partials/_LabUtilization.cshtml")
</div>
在_LabUtilization.cshtml
中,我将变量测试称为@test
。但是有错误,因为@test未定义。我应该怎么做才能在test
中调用变量_LabUtilization.cshtml
?
答案 0 :(得分:0)
使用某种模型向部分模型发送值
//your model
public class SomeModel
{
public string test {get;set;}
}
//you view
@model SomeModel
<div id="SettingsTabPanel" class="tabbable-line" style="padding-top:20px;">
<div id="ProjectTimeLine" class="tab-pane">
@{ var test = 10;
Model.test = test;
}
@test
</div>
@Html.Partial("~/Views/PortfolioResearch/Partials/_LabUtilization.cshtml", Model)
</div>
//your _LabUtilization partial
@model SomeModel
<span> @Model.test</span>