當添加客戶(客戶端)時,我有一個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>
感謝
要得到什麼方法(你已經證明是唯一一個沒有任何參數)。 –
你有理由,我修改我的get方法,並添加參數 – Sarra