asp.net mvc的呼叫下拉Ajax请求 [英] asp.net mvc calling dropdown ajax request
本文介绍了asp.net mvc的呼叫下拉Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
确定我有不同记录的记录格
再加上我有一个下拉作为列,以及(这应该去,只是救我选择的价值,回来同台演出,我要送些ID以及)。如何实现这一点。形式是在运动在我的code提交。
<使用(Ajax.BeginForm(SaveStatus,新AjaxOptions {=的onSuccessjobStatusChanged}))%
{%GT;
&所述;%= Html.Hidden(JobFormMain,item.int_JobFormMain)%GT;
<%:Html.DropDownList(的SelectedItem,JobHelper.GetSelectStatus(item.int_JobFormMain)为IEnumerable< SelectListItem>中新平变化{=this.form.submit();})%GT;
<%}%GT; 公众的ActionResult SaveStatus(INT?页的FormCollection形式,诠释ID = 0)
{
返回查看()
}
解决方案
我会使用jQuery绑定到下拉的变化事件,然后张贴价值,你的控制器动作。您可以将类分配到下拉列表,以方便使用jQuery选择。
<%= Html.DropDownList(的SelectedItem,JobHelper.GetSelectStatus(item.int_JobFormMain)为IEnumerable< SelectListItem>中新{@class =SelectedItemDropDown})%GT ;<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数()
{
$(。SelectedItemDropDown)。改变(函数()
{
$。员额(控制器/ SaveStatus,{ID:$(本).VAL()});
}
}
< / SCRIPT>
ok i have a record grid with different records
plus i have a dropdown as column as well (which ought to go and just save the value i have selected and come back on the same stage , i have to send some id as well) . how to achieve this . form is at the movement submitting in my code.
<% using (Ajax.BeginForm("SaveStatus", new AjaxOptions { OnSuccess = "jobStatusChanged" }))
{%>
<%=Html.Hidden("JobFormMain",item.int_JobFormMain) %>
<%: Html.DropDownList("SelectedItem", JobHelper.GetSelectStatus(item.int_JobFormMain) as IEnumerable<SelectListItem>, new { onchange = "this.form.submit();" })%>
<% } %>
public ActionResult SaveStatus(int? page,FormCollection form, int id = 0)
{
return View()
}
解决方案
I would use jquery to bind to the dropdown's change event, and then post the value to your controller action. You can assign a class to the dropdown to make it easy to select with jquery.
<%= Html.DropDownList("SelectedItem", JobHelper.GetSelectStatus(item.int_JobFormMain) as IEnumerable<SelectListItem>, new { @class = "SelectedItemDropDown" })%>
<script type="text/javascript">
$(document).ready(function()
{
$(".SelectedItemDropDown").change(function()
{
$.post("controller/SaveStatus", { id : $(this).val() });
}
}
</script>
这篇关于asp.net mvc的呼叫下拉Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文