2016-04-14 94 views
-1

當添加客戶(客戶端)時,我有一個Number的DropDownList,當我選擇RaisonSocial時應該得到相對於數字的值: Number和RaisonSocial在同一個表將DropDownList中的選定值從View Razor傳遞給控制器​​使用asp.net mvc

兩個屬性這是我controller'action:

[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(); 
    } 

這是我的看法://註冊:

@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal form-label-left", role = "form", @id = "demo-form2" })) 
      { 
       @Html.AntiForgeryToken() 

        @Html.ValidationSummary("", new { @class = "text-danger" }) 

        @*" Label de Numéro de Client"*@  
        <div class="form-group"> 
         <label for="No_" class="control-label col-md-3 col-sm-3 col-xs-12">N° Client</label> 
         <div class="col-md-9 col-sm-9 col-xs-12"> 

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




         </div> 
        </div> 

        @*" Label de Raison Sociale"*@ 
        <div class="form-group"> 
         <label class="control-label col-md-3 col-sm-3 col-xs-12" for="RaisonSociale"> 
          Raison Sociale 
         </label> 
         <div class="col-md-6 col-sm-6 col-xs-12"> 
          <input type="text" name="RaisonSociale" value="@ViewBag.Remise" readonly="readonly" class="form-control col-md-7 col-xs-12" /> 
         </div> 
        </div> 

感謝

+0

要得到什麼方法(你已經證明是唯一一個沒有任何參數)。 –

+0

你有理由,我修改我的get方法,並添加參數 – Sarra

回答

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; 

} 
+0

我修改我的下拉onchange函數,並添加到註冊參數名稱字符串ddlvalue,但它doesen't工作 – Sarra

+0

我得到這個網址:/帳戶/註冊? ddlvalue = [object%20HTMLSelectElement] – Sarra

+0

修改更改功能,在下拉列表中輸入this.value –

相關問題