0
我想要做的是我有2个选择框设置在视图中一个选择器持有我不同的配置文件源。第二个根据您选择的来源保存配置文件名称。问题在剃须刀内调用javascript函数如果语句
我的问题是我想要一个特定的值,放在数据库中对照配置文件源进行测试,所以我根据所选源选择正确的配置文件。
这就是我目前的观点:
<div class="managerField">
<label for="Source Selector" class="label">Select Source:</label>
<select name="SourceSelector" form="PostScheduler" class="select-style" onchange="sourceSelect(this.value)">
<option value="" selected>Please Select Source</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
<div class="managerField">
<label for="ProfileSelector" class="label">Select Profile:</label>
<!-- POPULATE BASED ON SOURCE SELECTED -->
<select name="Profile Selector" class="select-style">
@foreach (var p in Model.SocialProfiles.Where(pr => pr.SocialProfileTypeID == sourceSelect(SourceSelector))
{
<option value="@p.SocialProfileID">@p.ScreenName</option>
}
</select>
</div>
@section Scripts
{
<script type="text/javascript">
function sourceSelect(el)
{
if (el == "") return 0; // Will need to catch
if (el == "1") return 2;
if (el == "2") return 6;
if (el == "3") return 15;
}
}
任何帮助,将赫然赞赏。
现在运行它会发生什么?如果将'return'语句更改为'console.log',输出是什么?这种看起来很好,所以目前还不清楚问题是什么。 – Yuck
你是说你的脚本标签中,你的if语句是一个剃须刀if和if javascript if。脚本部分的输出html(浏览器中的查看源代码)是什么? –
哦,你正试图在Razor语句中使用JavaScript函数。这是行不通的。剃刀是一个视图引擎。它只是发布文档(HTML,JavaScript等),但它无法访问实际的JavaScript代码。您需要加载这两个列表并更改客户端上的显示,或者根据所做的第一个选择使AJAX调用获取适当的列表。 – Yuck