发送带有选择列表的表格 [英] Sending form with Select List

查看:129
本文介绍了发送带有选择列表的表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码将选定项目的值从视图发布到控制器

I am using this code to post value of selected item from the view to the controller

@using (Html.BeginForm())
{
        @Html.DropDownListFor(model => model.MyVar, (SelectList)ViewData["List"])
        <button name="Button" value="Valider">Valider</button>

}

有没有办法送价值时,在选择列表中选择变化(无需点击按钮)?

Is there a way to send the value when the selection change in the select list (without the need to click on the button) ?

推荐答案

是的,您可以通过 JQUERY ,在下拉选择更改中,通过jquery发布表单:

yes you can do it via JQUERY, on dropdown selection change post the form via jquery:

添加ID进行下拉:

@Html.DropDownListFor(model => model.MyVar, (SelectList)ViewData["List"], new { id="SomeId"})

并编写jquery事件:

and write jquery event:

$(function(){

    $("#SomeId").change(function(){

        $(this).closest("form").submit(); // this will post the form
    });   

});

这篇关于发送带有选择列表的表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆