mvc html.dropdownlist onchange,c# - @Html.DropDownListFor onchange is not calling the mentioned Acti...

博客内容讲述了在ASP.NET MVC应用中,作者试图通过Dropdownlist的onchange事件调用`GetAuditTasksList`控制器方法,但实际触发的是`Edit`方法并提交了表单。问题在于事件处理函数`testing()`中,表单提交指向错误的方法,导致数据被不期望地更新到数据库。
摘要由CSDN通过智能技术生成

I am trying to call a controller method "GetTasksList" onchange of dropdown value in view. However onchange of dropdown, the "Edit" method of Controller is being called and submitting the form to database. This is undesirable because I am trying to fetch a list of tasks from the database based on the dropdownvalue.

View

@Html.DropDownListFor(x => x.AuditDecision, (SelectList)ViewBag.ListofAuditDecision, "Please select", new { @class = "form-control input-10", id = "AuditStatus", onchange = "testing();", @style = "width: 300px;" })

function testing() {

alert("in testing");

document.forms[0].action = 'GetAuditTasksList';

// window.location.href = 'GetAuditTasksList';

document.forms[0].submit();

}

The control goes to below method

[HttpPost]

[ValidateAntiForgeryToken]

public ActionResult Edit(Audit audit)

{

//submitting to database

}

instead of

[HttpPost]

[ValidateAntiForgeryToken]

public ActionResult GetAuditTasksList(Audit audit)

{

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值