2011-03-18 67 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