Javascript 未定义MVC函数
我试图从@onchange事件调用“demo”函数, 该函数在@functions{}节中声明。 当事件被触发时,它表示“demo”未定义 有人知道吗 霉菌代码:Javascript 未定义MVC函数,javascript,asp.net-mvc,function,view,Javascript,Asp.net Mvc,Function,View,我试图从@onchange事件调用“demo”函数, 该函数在@functions{}节中声明。 当事件被触发时,它表示“demo”未定义 有人知道吗 霉菌代码: @Html.DropDownList("TransactionType", new SelectList(Enum.GetValues(typeof(Forex.Reports.ReportValueType))), "Transaction Type", new { @class =
@Html.DropDownList("TransactionType",
new SelectList(Enum.GetValues(typeof(Forex.Reports.ReportValueType))),
"Transaction Type",
new
{
@class = "form-control",
@id = "type",
@onchange = "@demo(GetDropDownValue('type'))"
}
)
@functions{
public void demo (string selectedValue)
{
IEnumerable<Mt4Transaction>
results =
from result in Model
select result;
switch (selectedValue)
{
case "Withdrawal":
{
results =
from result in Model
where result.Profit > 0
select result;
}
break;
case "Deposit":
{
results =
from result in Model
where result.Profit < 0
select result;
}
break;
case "UnidentifiedProfit":
{
results =
from result in Model
select result;
}
break;
}
Html.RenderPartial("MonetaryTransactionsPartial", results);
}
@Html.DropDownList(“TransactionType”,
新建SelectList(Enum.GetValues(typeof(Forex.Reports.ReportValueType)),
“交易类型”,
新的
{
@class=“表单控制”,
@id=“type”,
@onchange=“@demo(GetDropDownValue('type'))”
}
)
@功能{
公共void演示(字符串selectedValue)
{
数不清
结果=
从结果到模型
选择结果;
开关(selectedValue)
{
“撤回”一案:
{
结果=
从结果到模型
其中结果。利润>0
选择结果;
}
打破
“押金”一案:
{
结果=
从结果到模型
其中结果。利润<0
选择结果;
}
打破
“身份不明的财产”一案:
{
结果=
从结果到模型
选择结果;
}
打破
}
RenderPartial(“MonetaryTransactionSpatial”,结果);
}
谢谢,
Yaniv
public void demo()
是服务器端代码。@onchange=“@demo()
是客户端代码。您不能在浏览器中运行服务器端代码,除非您使用ajax调用服务器方法(或重定向到方法),并且作为旁注,不要执行.change()中的代码
一个
事件-每次用户使用键盘浏览项目时都会触发该事件(在您的情况下,您需要进行ajax调用以更新局部视图,这样会对性能产生重大影响)。有一个单独的按钮来触发ajax调用。我得到了一个局部视图,每次我得到结果时都会呈现该视图,您能为ajax调用编写一个示例吗?我知道:)-您需要使用ajax调用服务器方法(传递所选选项的值)返回部分视图,然后更新DOM。请参阅一个示例,为什么我不能从onchange调用它?这是我需要的行为。。。