2011-03-18 64 views
1

我在我的頁面上有DropDownListTextboxDropDownList節目從DataBase(Table "List"). 數據當我在DropDownList選擇一條線我希望看到它在Textbox,進行修改和該行存入DataBase(Table "Text")「OK」後。從DropDownList到文本框

請告訴我,該怎麼做?

代碼:

Controller.cs:

public ActionResult Create(Model model) 
    {   
     var viewModel = new ISMSViewModel 
     { 
      Model = new Model(), 
     }; 

     return View(viewModel); 

    } 

    [HttpPost] 
    public ActionResult Create(Model model, int i) 
    { 
     try 
     { 
      sysDB.AddToActives(model); 
      sysDB.SaveChanges(); 

      return RedirectToAction("Browse"); 

     } 
    } 

ListText.ascx:

  <%: Html.EditorFor(model => model.Model, new { Lists = Model.Lists } %> 

      <%: Html.Label("List") %> 
      <%: Html.DropDownList("ListId", new SelectList(ViewData["Lists"] as IEnumerable, "ListId", "Name", Model.ListId)) %> 

      <%: Html.Label("TextBox") %> 
      <%: Html.TextBoxFor(model => model.TextBox) %> 
      <%: Html.ValidationMessageFor(model => model.TextBox) %> 

回答

2

爲此,您需要編寫一些JavaScript。

處理onchange事件的下拉

<%: Html.DropDownList("ListId", new SelectList(ViewData["Lists"] as IEnumerable, "ListId", "Name", Model.ListId), new {@onchange="setVal(this)"}) %> 

對你的看法 內head

<script type="text/javascript"> 
function setVal(obj) 
{ 
document.getElementById("TextBox").value=obj.value; 
} 
</script> 
+0

謝謝你回答我的問題,但我無法實現我的這個項目的解決方案。你會如此善良,給我一個關於這個解決方案正在進行的簡單項目的鏈接。請不要嚴格評判,我是初學者。 – sphinx 2011-04-04 05:53:20

+0

@sphinx你可以給我你的解決方案,我會做出改變,可以嗎? – 2011-04-04 09:56:26