使用asp.net mvc将DropDownList中的SelectedValue从View Razor传递到Controller

时间:2016-04-14 12:36:06

标签: asp.net-mvc

添加客户(客户端)时,我有一个NumberD的DropDownList,当我选择RaisonSocial时应该得到相对于该数字的值: Number和RaisonSocial是同一个表中的两个属性

这是我的控制人员:

$ cat a
hello
ip: 23
bye
and this is
id: 23
hehe
done
$ awk -v var=23 '$0~"ip: " var,/id: /' a
ip: 23
bye
and this is
id: 23

这是我的观点://注册:

  [HttpGet]
public ActionResult Register()
    {
        ViewBag.No_ = new SelectList(dbCustomer.AURES_GROS_Customer.ToList(), "No_", "No_");

        ApplicationUser user = new ApplicationUser();
        // Get Raison Sociale relative to No_ selected 
       user.RaisonSociale = context.Users.First(c => c.No_.Equals(NumClient)).RaisonSociale;
        ViewBag.Remise = user.RaisonSociale;
        //ViewBag.Remise= new SelectList(dbCustomer.AURES_GROS_Customer.ToList(), "Name", "Name");


        return View();
    }

由于

1 个答案:

答案 0 :(得分:1)

修改你的下载onchange功能

@Html.DropDownList("No_", (SelectList)ViewBag.No_, " -- Selectionner numéro de Client -- ", new { @id="test", onchange = "getddlVal(this.value)" })

的Javascript

function getddlVal(selectedval)
{
        window.location = '/Controller/action?ddlvalue=' + selectedval;

}